/Practice

Coding hacks and tricks reels

Coding hacks and tricks1 / 9

Every coding round, same six steps

1

Clarify

Restate the problem. Ask about input size, duplicates, negatives, empty input, and what to return.

2

Examples

Work one normal and one edge example by hand. It catches misreads before they cost you.

3

Brute force

Say the obvious solution and its complexity. It proves you understand the problem and gives a fallback.

4

Optimise

Match the signals to a pattern. Name the bottleneck and the data structure that removes it.

5

Code

Write clean code with good names. Talk while you type. Leave helper details for later if needed.

6

Test

Run your examples line by line, then edge cases. Fix bugs calmly and state the final complexity.

The six-step method
#method
Coding hacks and tricks2 / 9

n tells you the target complexity

n ≤ 10
→ O(n!) · Permutations, brute-force backtracking
n ≤ 20
→ O(2ⁿ) · Subsets, bitmask DP
n ≤ 500
→ O(n³) · Triple loops, interval DP, Floyd–Warshall
n ≤ 5,000
→ O(n²) · Pairs, 2D DP
n ≤ 10⁶
→ O(n log n) or O(n) · Sort, heap, two pointers, hashing, BFS
n ≥ 10⁹
→ O(log n) or O(1) · Binary search, maths
Read the constraints first
#complexity
Coding hacks and tricks3 / 9

Hear this, reach for that

Sorted array, find a pair
→ Two pointers
Contiguous subarray or substring
→ Sliding window / prefix sums
Linked list cycle or middle
→ Fast and slow pointers
'Minimum X such that…'
→ Binary search on the answer
Have I seen the complement?
→ Hash map
Next greater or smaller
→ Monotonic stack
Top K, Kth, merge K
→ Heap
Meetings, ranges, overlaps
→ Sort by start, sweep
Signal → pattern
#patterns
Signal → pattern, part 2
TypeScript power tools
Bugs that cost offers
Quick check: constraints
Quick check: signals
Quick check: BFS