Skip to main content

Interview Tips

Coding Interview Tips — How to Solve LeetCode Problems by Pattern

Based on problem constraints, use these heuristics to identify possible approaches when unsure.

Arrays & Strings

Condition Approach
Input is sorted Binary search or two pointers
Need O(1) lookup or existence check Hash table (set or map)
Problem requires in-place modification Two pointers or index swap
Common prefix or string matching Map counting or Trie
XOR, toggling, or bit flags Bit manipulation

Subarrays & Sequences

Condition Approach
Max or min subarray sum or length Dynamic programming or sliding window
Sliding window max or min Monotonic deque
Next greater or smaller element Monotonic stack
Range sum query Prefix sum, Binary Indexed Tree, or segment tree

Trees & Graphs

Condition Approach
Tree traversal or path problem DFS (recursion or stack) or BFS (queue)
Graph traversal or connected components DFS / BFS / Union-Find
2D grid connectivity or shortest path BFS or DFS or DP on grid
Grouping or merging disjoint sets Union-Find or DFS
Task ordering with dependencies Topological sort

Linked Lists & Stacks

Condition Approach
Cycle detection or finding midpoint in a linked list Fast and slow pointers
Need to simulate recursion iteratively Explicit stack

Sorting & Intervals

Condition Approach
Top K or least K elements Min/max heap, Quickselect, or bucket sort
Merging multiple sorted sequences Merge sort pattern or min-heap
Overlapping interval handling Sort by start time, then sweep line
Processing a continuous data stream Heap or custom data structure

Optimization

Condition Approach
All permutations, combinations, or subsets Backtracking
Count ways or divide problem optimally Greedy (if provable) or Dynamic Programming

General

Condition Approach
None of the above fit Hash map or set — O(1) time, O(n) space
Want to avoid extra space Sort the input first — O(n log n) time, O(1) space
🎙️ Interview Room Psychology

The "Thinking Out Loud" Framework: How to Communicate Under Pressure

In tier-1 tech interviews (FAANG / Big Tech), interviewers are not evaluating whether you have memorized code syntax; they are assessing what it is like to collaborate with you as a software engineer on a production team. Candidates who remain silent for 15 minutes and produce code receive lower signals than candidates who vocalize trade-offs.

Pacing the 45-Minute Interview

  • 00–05m: Requirements clarification & constraint confirmation
  • 05–15m: High-level design, naive approach & trade-off discussion
  • 15–30m: Clean modular implementation
  • 30–40m: Manual dry run with non-trivial test case & edge checks
  • 40–45m: Time/space analysis & your questions for interviewer

What to Say When You Are Stuck

Never freeze or apologize. Instead, externalize your mental model: "I'm considering whether a monotonic stack or a two-pointer approach fits this condition better. The challenge is preserving the original indices while maintaining order. Let me write out a 4-element trace on the whiteboard to see the invariant."

Jump to section

Buy me a coffee
Daily Practice
0/0