Big-O — Analyse Every Solution
You must state time and space complexity for every solution, unprompted. Interviewers grade this heavily.
- Know the ladder: O(1) < O(log n) < O(n) < O(n log n) < O(n²) < O(2ⁿ).
- Binary search and balanced-tree operations are O(log n); sorting is O(n log n).
- A nested loop over the same array is usually O(n²) — a signal to look for a hashmap optimisation.
- Always mention space complexity too, including recursion stack depth.
The Data Structures You Must Know Cold
The 60% that appears in most rounds. Know the operations and their complexities.
- Arrays & Strings — the most common; master two-pointer and sliding-window techniques.
- HashMap / HashSet — O(1) average lookup; the go-to for 'have I seen this before' problems.
- Stack & Queue — parentheses matching, next-greater-element, BFS.
- Linked List — reversal, cycle detection (Floyd's fast/slow pointers), merge.
- Trees & BST — traversals (inorder/preorder/postorder), height, lowest common ancestor.
- Heap — top-K problems and priority queues.
- Graphs — BFS/DFS, and know when a problem is secretly a graph.
The Patterns That Solve Most Problems
Interview problems are variations on a small set of patterns. Recognising the pattern is 80% of the solve.
- Two pointers — sorted-array pair sums, palindrome checks.
- Sliding window — longest/shortest substring or subarray meeting a condition.
- Fast & slow pointers — cycle detection, middle of a list.
- Hashing for O(1) lookup — two-sum, anagrams, duplicates.
- BFS/DFS — trees, grids and graphs.
- Dynamic programming — overlapping subproblems (climbing stairs, knapsack, LIS).
How to Solve a Problem Out Loud
The process is scored as much as the answer. Follow a visible method.
- Restate the problem and confirm constraints and edge cases (empty input, duplicates, negatives).
- State a brute-force approach and its complexity first — it shows you can start.
- Then optimise: 'Can a hashmap remove this inner loop?'
- Code cleanly, then dry-run with a small example.
- State the final time and space complexity without being asked.
A Realistic Study Plan
Consistency and pattern coverage beat grinding hundreds of random problems.
- Weeks 1–2: Arrays, strings, hashmaps, two pointers, sliding window.
- Weeks 3–4: Linked lists, stacks, queues, recursion.
- Weeks 5–6: Trees, BST, BFS/DFS, heaps.
- Weeks 7–8: Dynamic programming and graph problems.
- Throughout: the 'Blind 75' list covers the highest-yield patterns; time yourself at 20–30 min/problem.
Common Interview Questions & Answers
Q1. How would you check if a string has all unique characters?
The clean approach is a hash set: iterate the string, and for each character check if it is already in the set — if so, return false; otherwise add it. This is O(n) time and O(1) space if the character set is fixed, say 128 ASCII characters. If told not to use extra data structures, you can sort the string first in O(n log n) and check adjacent characters, or use a bit vector for lowercase letters.
Offer the optimal hashset answer, then the constraint-driven alternative — it shows range.
Q2. Explain the two-pointer technique with an example.
Two pointers uses two indices moving through a structure to avoid a nested loop. For finding a pair that sums to a target in a sorted array, place one pointer at the start and one at the end; if the sum is too small move the left pointer right, if too large move the right pointer left, until they meet. That turns an O(n²) brute force into O(n) time and O(1) space.
Always contrast the complexity against brute force to justify the pattern.
Q3. How do you detect a cycle in a linked list?
Use Floyd's fast-and-slow pointer algorithm: advance one pointer by one node and another by two nodes each step. If they ever meet, there is a cycle; if the fast pointer reaches null, there is none. It runs in O(n) time and O(1) space, which beats the O(n) space of storing visited nodes in a hash set.
Naming 'Floyd's algorithm' and the O(1) space edge over hashing is the differentiator.
Q4. What is the difference between an array and a linked list?
An array stores elements in contiguous memory, giving O(1) random access by index but O(n) insertion or deletion in the middle because elements must shift, and a fixed size in low-level languages. A linked list stores nodes with pointers, giving O(1) insertion or deletion once you have the node but O(n) access because you must traverse from the head, plus extra memory for pointers. You choose based on whether you need fast indexing or fast mid-list edits.
Frame it as a trade-off between access speed and insertion speed.
Q5. When would you use dynamic programming?
Use dynamic programming when a problem has overlapping subproblems and optimal substructure — meaning the optimal answer is built from optimal answers to smaller subproblems that recur. Classic signals include counting ways, min/max over choices, and 'can you reach' problems, like climbing stairs, coin change, knapsack, or longest common subsequence. You store subproblem results in a table (bottom-up) or memoise (top-down) to avoid recomputation, turning exponential recursion into polynomial time.
Naming 'overlapping subproblems' and 'optimal substructure' is exactly what interviewers listen for.
Common Mistakes to Avoid
Jumping straight to code without stating constraints or a brute force first
Forgetting to state time and space complexity
Not handling edge cases (empty input, single element, duplicates, negatives)
Grinding random problems instead of learning the underlying patterns
Going silent while thinking — interviewers cannot score what they cannot hear
Expert Tips
Learn patterns, not problems — one sliding-window insight solves dozens of questions
Always narrate: brute force → complexity → optimisation → dry run → final complexity
Time yourself at 20–30 minutes per problem to build exam pace
Keep a personal list of the 5 patterns you find hardest and drill only those
Pre-Interview Checklist
6 itemsFrequently Asked Questions
How many problems should I solve before interviews?
Quality over quantity — 150–200 well-understood problems covering every major pattern beats 500 solved mechanically. The 'Blind 75' is a strong, compact starting list.
Which language should I use in coding rounds?
The one you are fastest and cleanest in. Python is popular for its brevity; Java and C++ are equally accepted. Consistency matters more than the language.
Do I need dynamic programming for fresher rounds?
Basic DP (climbing stairs, coin change, subset problems) does appear. Master arrays, strings, hashmaps and trees first, then add DP — it is usually the last topic tested.
Ready to ace your next interview?
Practice with SpeakWell AI. Upload your resume → get resume-based questions → practice with AI interviewers → improve communication → track progress → get instant AI feedback.