DS-Algo-Practice

Coding question common Patterns

  1. Sliding Window
  2. Two Pointers or Iterators
  3. Fast and Slow pointers
  4. Merge Intervals
  5. Cyclic sort
  6. In-place reversal of linked list
  7. Tree BFS
  8. Tree DFS
  9. Two heaps
  10. Subsets
  11. Modified binary search
  12. Top K elements
  13. K-way Merge
  14. Topological sort
  15. 0/1 Knapsack
  16. Unbounded Knapsack
  17. Fibonacci Numbers
  18. Palindromic Subsequence
  19. Ad hoc/string manipulations
  20. Hash tables(checkout language-specific implementation of hashing)
  21. Array-related questions need to be practiced a lot because they need maximum logic, in my opinion. Only through practice will you learn certain intricate tricks.

Algo Visualization

  1. Visualize DS
  2. Visualize Algo

Tips & Tricks

Every interview prep should be divided into three stages:

  1. Start brushing up your concepts and practice a few easy-medium level questions just to get reacquainted with the coding platforms and such. Also, devise a proper timetable if you only have a few days to prepare because otherwise, you will end up wasting time on concepts you are strong at. (1–2 days)
  2. Start reading medium-hard questions and first solving them using a pen and paper. Trust me, don’t try to do it all in your head. It would be best if you use the pen and paper habit to tackle the intricacies of the question(I had to force myself to do this so that I would stop missing edge cases in the first attempt to finish the code quickly).Also, we can think better when we can visualize the problem, so please follow this one. Another thing to keep in mind is to analyze your performance and understand your weaknesses at the end of each day. Slowly you need to follow practices that can help you tackle those weaknesses. In this step, also make sure to bookmark concepts or questions you want to revise at the end. (5–6 days)
  3. Finally, when you get to a confident stage in all your basic data structures. Move to mock interviews, or prepare other soft skills like explaining your solution out loud or on pen and paper, or even practicing how to code in a google doc or on the whiteboard. Also, in the end, you need to revise the concepts that you marked in the previous step. (2–4 days)

MOTIVATION

Principle 1

Solve every problem There are so many easy leetcode problems that anyone can solve. Do NOT skip over them. Solve them as fast as you can and move forward. And by solving, I mean actually writing the code and getting all test cases passed.

Principle 2

Read Solution + Discussion Wrote code on your own and got all test cases passed? Congrats! However, that is not the end, it is very important to read the solution and discussions. More often than not there will be more than one approach to solve the problem. It is important to understand all the approaches. Leetcode discussion community is very good. Sort by most voted and pick any of the top few answers. Make sure you check out their code as well. The top coders write code very elegantly. There is a lot to learn from them even if you get the solution. Also reading the explanation will give you ideas on how to explain in the interview.

Principle 3

Do not spend more than 5–10 minutes thinking This might be a controversial opinion. According to me, you will only have a maximum of 10 minutes in an online test to think of a solution and less than 20 minutes to implement it. In an interview, you will have even less time as you will need to explain your approach, code and dry run etc. So if in the actual test you have less time, you should prepare accordingly. What I did was this, after 5 minutes, I give up and check the solution. If I don’t understand the solution, I bookmark it as red and leave it. If I understand the solution, I bookmark it as yellow.After a week or two, I come back and solve the yellow ones. This time I try to recollect the solution and solve it myself. If I fail, then I read the solution again and come back later. Most of the times I succeeded to recollect the solution. This is extremely effective because it will feel like I got the solution myself and I would feel confident I can solve similar questions now. Some advantages of this principle are:

  1. You didn't spend too much time “thinking”
  2. You understood the solution fast, it feels like progress
  3. If you recollect and implement it later, the concept will be ingrained in the mind
  4. Throughput — number of problems solved / day will be high
  5. Overall morale will be good because you are not spending time stuck

REAL WORLD FEATURES

  1. Netflix feature: Group similar titles (hashmaps)
  2. Facebook feature: Friend circles (DFS)
  3. Google Calendar feature: Find meeting rooms (Heaps)
  4. Amazon feature: Products in price range (BST)
  5. Twitter feature: Add likes (Strings)