4 ms·
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 inf
by aliyfarah 4y ago
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 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.