4 ms·
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.
by aliyfarah 4y ago
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.
- justinlloyd 4y agoI 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/ 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/ 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-list/ 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/ https://leetcode.com/problems/number-of-islands/ is 12 lines of BFS code. Coin Change (medium) https://leetcode.com/problems/coin-change/ 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.
- aliyfarah 4y agoLines 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 https://twitter.com/i/web/status/608682016205344768
- justinlloyd 4y agoYou 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.