Skip to content

Problem triage

Abstract

Strategies to solve the 48 problems of LeetCode Top Easy, written after solving them.

The strategies are purposely limited to these problems and don't try to extrapolate broader rules for solving a wider set of LeetCode problems.

Generated with love by AI.

Problem

When you are unsure which branch to choose

Strategy: Problem triage

  • Think about this
    • array/string single scan -> two pointers or hash
    • pair/complement/duplicate -> hash
    • sorted + boundary -> binary search
    • tree structure -> DFS or BFS
    • linked list -> slow/fast, dummy, reverse pointers
    • count ways / take-skip -> DP
    • exact bit behavior / constant space trick -> XOR or bit ops
    • parser / digits / overflow -> state machine
  • Avoid this
    • Do not start coding brute force before naming the pattern.
    • Do not ignore constraints like:
      • in-place
      • O(1) extra space
      • one pass
      • sorted
      • exactly one solution
  • Tell this to the interviewer
    • First say:
      • brute force
      • why it is too slow or space-heavy
      • the pattern that improves it
    • Then code the smallest standard template that fits.
  • See these problems