Cracking MAANG: How to approach solving algorithmic questions if you stuck?
Cracking MAANG: How to approach solving algorithmic questions if you stuck?

Cracking MAANG: How to approach solving algorithmic questions if you stuck?

When I started, I would spend 2 hours solving a single problem.

Spend 1-2 weeks on a topic, learn the data structure and basic algos behind it, then switch to another, and return to the previous topic again but later. Start with strings/arrays, move to linked lists, trees, and graphs, revisit topics over and over, learn dynamic programming concepts solve 1-2 weeks again.

General Problem-Solving Approach

  1. Read the problem, repeat it, understand it. Don’t immediately jump into coding!
  2. Understand inputs and outputs. Draw some examples on paper.
  3. Clarify requirements, ask clarifying questions, and understand constraints (edge cases). Example questions: Is it ASCII or Unicode? What is the max value? Is there a difference between capital letters and small letters?
  4. Check my questions lists here.

  5. Think about the solution in your mind. Divide problems into sub-problems. Come up with different ideas (ask whys, think about trade-offs, solve simpler versions, imagine helper functions - go from high level to low level).
  6. Evaluate the complexity and trade-offs.
  7. Think of a better alternative solution.
  8. Write code on paper.
  9. Debug your code on paper and test with new corner case inputs.
  10. Write code. Write clean code.
  11. Write tests. Positive, negative, with edge-cases.

More to read:

My Approach to Solve Difficult Problems

  • Draw examples on paper, window, whiteboard. Understand the input and output. Understand the logic of how the data changes over iterations, don't write code; just focus on understanding the problem.
  • Think about how you would solve this, and consider writing pseudocode. Use imaginary functions or helper functions to make the problem easier. Solve problem high level, to low level.
  • Solve simpler problem, remove some constraints of the same problem.
  • Still stuck? Watch the solution, and try to understand every every every single step. Understand the implementation/idea, but not the code. Don't try to memorize code.
  • Solve similar problems.
SuperMade with Super