It probably took me 2 full hours, and I only got it with a brute force approach and a butt-load of optimization to make it efficient later.
So, anyway, then I go to the discussion tab, and that's where everyone is chatting about this really cool, elegant, O(n) solution. But it's the kind of thing you would see in a CS textbook, not just come up with on your own. And I didn't see any proofs, so I still don't know that it _really_ works. But I do see lots of examples of exactly how to implement it.
My question is; what's the point then? Are you supposed to not look at the discussion and beat your head against the wall trying to best Donal Knuth, or do you look at the discussion and then just copy it all over with your brain totally turned off? I don't get it.
Oh, here it is, in case anyone is wondering:
https://leetcode.com/problems/container-with-most-water/
I think that if you're stuck on a problem for more than 30 minutes, it's better to go read the solution and learn from it than to keep struggling. (Then go back a week later and see if you can solve the problem from memory).
Opinions certainly differ on whether leetcode makes for a good interviewing process. On your specific problem, there are a ton of similar problems where you need to traverse possible solutions in a particular order to be efficient. I regularly see similar problems at work.
Of course trying to make this deduction during an actual interview when one or multiple people are watching you is an entirely different problem. Hopefully leetcode will give you enough practice to recognize patterns so that you don't need to think too deeply during interviews.
Well, LeetCode is a CS-textbook-problems kind of site.
You use it however you like. While I was searching for my first job, I spent some time solving problems and optimizing them, half to keep my skills from degrading after college, and half just for fun. I just treated it like a puzzle collection and had a good time with some of the more open-ended questions. I'm sure it'd be useful to help learn a new language as well. I'm not convinced it's effective as a general skill-improvement tool, though.
In reality, after you practice a lot of these problems, you realize that there are only a few broad categories and that most of them just use what you learned in school. You just have to practice to become fast.
I copied my solution elsewhere ran it, and it worked fine.
The only thing I could guess is the input wasn't what I was expecting, but I couldn't verify what input leetcode was actually giving me, so I just walked away.
The whole thing was a waste of time anyways. I still have yet to ever get a leetcode question during an interview and I've been doing this almost a decade now.
Then again, I don't try and get jobs at FAANG companies or FAANG wannabes.
We have yet to see outsized results from the leetcode group, but we have seen outsized results from the pre-non-leetcode group.
Results matter, as the leetcode dipshits would say.