TL;DR: Read first, plan briefly, ship iteratively, and test as you go. Small feedback loops beat big rewrites.
Read First, Type Later
Skim the entire prompt, examples, and constraints before writing any code. Identify the input format, output format, edge cases, and the maximum input sizes. Mark ambiguous lines and infer reasonable assumptions from the examples. This two‑minute scan often prevents fifteen minutes of rework.
Build a One‑Minute Plan
- State the approach in one sentence (e.g., "two‑pointer scan after sorting").
- Note the expected complexity (e.g., O(n log n) for sort + linear pass).
- Write down top three edge cases to test once a draft is ready.
Budget Your Time
Split the timer: roughly 20% reading and planning, 50% implementing, 30% testing and polishing. If you are still designing after the first third, lock an approach and start coding. A correct O(n log n) solution beats an unfinished O(n) idea.
Complexity Guardrails
- Prefer linear scans and hash maps for frequency/count lookups.
- Reserve sorting for global ordering needs or binary search pivots.
- Reach for stacks/queues for monotonic or sliding window problems.
Implement in Small, Testable Steps
Code the skeleton first: function signature, parsing, and a return stub. Then implement the core logic in short blocks. After each block, run against a tiny example you control. Early feedback is faster than tracing a long final solution.
Lightweight Test Cases
- Trivial case (empty or single element).
- Typical case from the prompt.
- Edge case that stresses boundaries (duplicates, negatives, very large values).
Debugging Under Pressure
When output is off, isolate the smallest failing input and print intermediate state near the suspected branch. Compare the state to what you expect after each step. Remove prints once fixed to keep the submission clean.
Common Pitfalls Checklist
- Off‑by‑one in loops or window bounds.
- Sorting comparator mistakes (ascending vs. descending, stability needs).
- Mutating references unintentionally (shared arrays or objects).
- Integer division vs. floating point when averaging.
Data Structures You Should Reach For
- Hash Map / Set: membership, frequencies, visited states.
- Heap / Priority Queue: k‑largest, scheduling, Dijkstra.
- Deque: sliding windows with O(1) amortized updates.
- Union‑Find: connectivity, cycle detection, Kruskal.
Before You Submit
- Scan for unused variables and leftover debug prints.
- Confirm complexity fits the largest constraint.
- Re‑run the three lightweight tests and one fresh case.
Practice Targets
Focus on patterns that reappear: two pointers, sliding window, binary search on answer, prefix sums, greedy with proof, and classic graph routines (BFS/DFS, Dijkstra, topological sort). Build a small notebook of pattern summaries you can recall quickly.
Want more preparation tips? Check related topics on sorting strategies, window techniques, and graph fundamentals in your study notes.
