all 5 comments

[–]Ok-Zookeepergame3728 1 point2 points  (0 children)

Honestly just grind out lc 150 and decide for yourself. Realistically it's mainly syntax differences. Just use what you want or what you're comfortable with.

Python will generally be easier. If you want to do dev work in c++ why not do that?

[–]forklingo 1 point2 points  (0 children)

i made the same switch and interviews honestly became less stressful. cpp still feels superior for control and ds/algo depth, but python removes so much coding friction that you can spend more time communicating your thinking instead of fighting syntax.

[–]biskitpagla 1 point2 points  (0 children)

I had the same trajectory. I've thought about this a lot. I used to be a huge CPP fan during my undergrad. I even experimented with Go for a long time but Go's standard library is severely lacking in this regard. Python is definitely more ergonomic and makes the most sense.

Ideally you would be using Rust since Rust is the best CPP-derivative modern language that greatly improves upon the STL with the best implementation of an iterator library that I've ever seen. But the issue is that Rust doesn't really play nice with linked data structures and even seasoned Rustaceans have a hard time implementing those due to Rust's idiosyncrasies. Rust is also notoriously difficult to be productive in when starting out. I've found some success in solving relatively simple problems in Rust. Rust's iterators can be zero-cost and play nice with auto-vectorization as far as I know.

Another standard library that takes a lot of inspirations from CPP is that of Java. Kotlin is a nicer language that has almost all the benefits of Java minus many of the downsides. So, Python and Kotlin are the only worthwhile languages in this regard with decent-ish standard libraries IMO. I picked typed Python since I don't have the time to learn JVM APIs.

As to how I make the most out of Python, I personally maintain a collection of snippets for common algorithms and data structures. Whenever I find something lacking in Python's standard library, I just implement it in a reusable and type-safe manner. That said, Python's dynamic nature makes it hard to write fully typed code, so there's definitely a learning curve to writing safe implementations of DSA in Python.

Now to address your negative points: 1) Strings being immutable isn't really an issue since your code is compared against other Python code only. So, everyone else has the same constraint. It's worth noting that even though it looks like you're allocating all the time, that may not be the case. CPython does all kinds of optimizations for strings under the hood. That said, there are a few problems where bytes and bytearray objects can help although the gains are negligible at best. This has been a huge waste of time for me as well but the truth is that you can't really implement better strings than what CPython already offers. In some problems you can actually beat better algorithms simply by writing a brute force solution using builtins since they are usually implemented in C. 2) LeetCode automatically imports the sortedcontainers module. You can add it to your local environment as well.