Eg: Tonight I spent 2 hrs on solving LC 652. Find Duplicate Subtrees. My own solution is to do a BFS traversal of the tree, and while traversing, keep a hashmap where the key is the value at each node, and the value is the list of nodes with that value. And I check whether a node's value is already in that tree, and if so, check if all the nodes at that value seen before is the same as the current one, using a helper function called 'IsSameTree' that checks if two nodes represent the same tree recursively. It took me about 10 mins to write working solution to the above, and surprising after a few minor bugs it passed most test cases until it hit Time Limit Exceeded. Then I realize this is too brute force. Then I spent 40 mins trying to optimize and failed miserably. I looked at the top voted solution and it's nothing short of a stroke of genius. It does a post order traversal where during each node, it serializes that node (using either pre-order or post-order) to a string, and put that string as key to a hashmap. And checks if the current node's serialization is seen exactly once before, and if so, add the node to result. Voila! Like, if you are given this problem and haven't seen a very similar one before, what thought process allows you to come up with this solution? Just knowing about BFS, DFS, Post/Pre order traversal does not help here. You have to hit upon the idea of using serialization too. And put them all together. And there's even one more subtitle point: as you serialize a tree, you have to do it either post or pre-order, but never in-order as it can give same representation on 2 diff trees( this is a point I can see by doing by example but cannot intuitively understand why, should I try to memorize this tidbit about serialization?). In this case, what is the 're-usable' pattern I should've taken away here? DFS/BFS/Post-pre order traversals I already know about. It seems the only re-usable pattern is "when finding duplicate subtrees, serialize every node". That's hardly reusable. And that's my experience doing all these problems.
You donât have a high enough level in CS to pass this question. Some would come up with the right solution in 40 min. They would pass and get the job. Thatâs todayâs competition.
đ
The takeaway is serialization is one of the patterns. So next think when you think of duplication or finding repititiojs you'll think of serialization of some sort.
Welcome to the rat race
How can I solve the famous patterns without solve all Leetcode problems ? Any recommendation
Cracking the coding interview. This problem is also there
I don't buy the argument that being a good computer scientist by your definition is required to build high quality software. High quality is more about discipline, focus, and testing than coming up with clever solutions reducible problems
Key is to be a cat in the rat race. Rats come to you running.
I have done many interviews recently and cleared G/FB/others. In each of these I have seen ~50% of the questions asked or something very similar. I have solved a total of 1500 questions, ~500 LC questions + almost 1000 others on geeksforgeeks + elements of programming interviews book + other books and websites It takes either a genius or so much dedication and with that even FB Interview seemed easy to me. I know I am not very smart but I am so dedicated both in interview preparation and in my job, which I think isnât something bad
From your experience how can I land a job as soon as possible in Amazon, apple or other fang . I have 3 yoe outside USA. I just started to study DS and algorithms and solve 70 LC so far . I started month ago. Any recommendations. Iam unemployed now. Iam a mom as well but I start to send my baby to daycare to be dedicated to study .
This thread is making me hyperventilate
I've noticed the same thing on many questions.