Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

For years I have run in terror at the leetcodes I might be thrown by a tech company that thinks it is a FANG.

Looking at the "Blind 75 Must Do Leetcode" problems, I must say, I am disappoint.

I just spent four hours on a Friday evening going through each of the problems, and have so far solved 40+ of them, in a less than optimal fashion for the most part, but solved and "correct" to pass the test cases. Some of them were so dazzling easy (Coins, Sum2, Robber, Robber II, Word Search II), that I sat there for a good few seconds and thought "That cannot be it, surely?!?"

Am I missing something?



> in a less than optimal fashion for the most part, but solved and "correct" to pass the test cases

You wouldn’t get through the interview. Most questions have a very easy brute force solution, but the answer they’re looking for is the optimal one. There’s also time constraints. Figure out the runtime complexity of your answer and compare it to the solutions.


Understood. So what I should be doing is trying create optimal solutions. Obviously completely optimal solutions on some of them could take hours, if not years to come up with. Those would be "you either know it or you don't" or you're the equivalent of Mozart when it comes to code. I am thinking I will work on some of those solutions today.


> Obviously completely optimal solutions on some of them could take hours, if not years to come up with.

Yep. Once you know the common patterns then most of the easy questions are pretty easy to solve optimally in 10-15 minutes. A lot of the hard questions seem impossible unless you’ve seen the problem before and I’m not sure what an effective strategy for those is.


Please stop lying, you absolutely did not solve 40 leetcode problems in 4 hours. That’s 6 minutes per question, most competitive programmers can’t even do that.


I have nothing to gain by lying. You're logic is flawed because you're assuming all questions took six minutes. Rotate Image, Robber II were all under two minutes, many others too. Coin Change and Robber and Merge Two Sorted Lists were under a minute. That leaves plenty of time to solve slightly more difficult problems. A half-dozen or so lines of C, C# or Python solves most of the problems in the set of problems that I tackled.

Have you looked at these problems? They're trivial.

Rotate Image (medium) https://leetcode.com/problems/rotate-image/) is 7 lines of code, because I have to use a temporary variable to do the swap. It is a simple matrix transpose. 5 lines if I could allocate more memory.

Merge Two Sorted Lists (easy) https://leetcode.com/problems/merge-two-sorted-lists/ is 6 lines of code. Walk two lists and do a comparison.

Remove Nth Node from End of List (Medium) https://leetcode.com/problems/remove-nth-node-from-end-of-li... is 7 lines of code. Create a stack, walk the list, pop off the stack, remove the node from the list.

Number of Islands (medium) https://leetcode.com/problems/number-of-islands/ is 12 lines of BFS code.

Coin Change (medium) https://leetcode.com/problems/coin-change/ is 5 lines of code.

I did not provide optimal solutions, which may be why competitive programmers take more time to solve the problems. I will see how I do when I start hitting on some of the hards.


Lines of code has nothing to do with the difficulty of the question, especially for recursion/backtracking types. "Invert a binary tree" is an example of an infamous question [1] that a lot of people stumble on and it's only 3 lines of code.

I shouldn't have called you a liar though, just saying those are very impressive results for someone who has never done these questions before if true.

[1] https://twitter.com/i/web/status/608682016205344768


You are correct, lines of code is nothing to do with the difficlty of the problem. I spent close to three weeks writing 12 lines of Python. Two of which consisted of print statements. A "clean-up" pass removed three more lines. I consider that to be some of the hardest code I've written in recent memory.

If I was asked to invert a binary tree on a whiteboard I would stumble too. Inverting a binary tree, I can walk through the algorithm, or I can bang out the code. And yes, it's three lines of code, but I had to look up what "invert a binary tree" means. Put a pen in my hand and I'd freeze up. It is trivial to solve through either recursion or iteration. I understand how to, but if I was asked to solve it in an interview, I'd definitely question why. I cannot think of a single instance whereby I'd want to legitimately flip a free left to right in its entirety. I can think of dozens of esoteric tree operations that I would need, and have used, but inverting/flipping left-to-right completely is not one of them.

I consider the person in that tweet far smarter than me.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: