PATTERN 1: Simple Traversal & Accumulation
D
Qubits of DPK
April 11, 2026
Core DSA
Core Idea (lock this)
“Scan once. Maintain minimal state. Compute answer incrementally.”
No sorting.
No hashing.
No sliding window.
No recursion.
Just disciplined linear thinking.
If you struggle here → later patterns collapse.
How to Recognize This Pattern (CRITICAL)
Think Pure Traversal when:
- Single pass (or fixed small passes)
- No dynamic resizing window
- No auxiliary data structure needed
- You maintain 1–3 running variables
- Answer builds as you scan
Trigger words:
- “maximum / minimum”
- “count”
- “running”
- “track”
- “difference”
- “scan array”
If you can solve it with 2–3 variables → Pattern 1.
30 MUST-DO INTERVIEW PROBLEMS
(10 Easy → 10 Medium → 10 Hard)
EASY (1–10): Traversal Muscle Memory
Goal: zero hesitation while scanning.
- #LC #1920 — Build Array from Permutation - COMPLETED
- #LC #1480 — Running Sum of 1D Array - COMPLETED
- #LC #2011 — Final Value of Variable After Operations - COMPLETED
- #LC #2114 — Maximum Number of Words Found in Sentences - COMPLETED
- #LC #485 — Max Consecutive Ones - COMPLETED
- #LC #724 — Find Pivot Index - COMPLETED
- #GFG — Find Largest Element in Array - COMPLETED
- #GFG — Second Largest Element - COMPLETED
- #GFG — Leaders in an Array - COMPLETED
- #GFG — Check if Array Is Sorted - COMPLETED
After these:
You should scan arrays without thinking about syntax.
️ MEDIUM (11–20): Multi-Variable State Control
Now interviews test clarity.
- #LC #53 — Maximum Subarray - COMPLETED
- #LC #121 — Best Time to Buy and Sell Stock (1 Transaction) - COMPLETED
- #LC #169 — Majority Element - COMPLETED
- #LC #665 — Non-decreasing Array
- #LC #283 — Move Zeroes - COMPLETED
- #GFG — Equilibrium Point - COMPLETED
- #LC #152 — Maximum Product Subarray - COMPLETED
- #LC #845 — Longest Mountain in Array - COMPLETED
- #LC #674 — Longest Continuous Increasing Subsequence - COMPLETED
- #LC #2765 — Longest Alternating Subarray - COMPLETED
Interviewers watch for:
- Clean reset logic
- Handling negatives
- Maintaining 2–3 states simultaneously
HARD (21–30): Traversal Under Pressure
No tricks. Just logic control.
- #LC #122 — Best Time to Buy and Sell Stock II - COMPLETED
- #LC #918 — Maximum Sum Circular Subarray - COMPLETED
- #LC #238 — Product of Array Except Self - COMPLETED
- #LC #414 — Third Maximum Number - COMPLETED
- #LC #1014 — Best Sightseeing Pair - COMPLETED
- #LC #1566 — Detect Pattern of Length M Repeated K or More Times - COMPLETED - COMPLETED
- #LC #896 — Monotonic Array - COMPLETED - COMPLETED
- #LC #1752 — Check if Array Is Sorted and Rotated - COMPLETED - COMPLETED
- #LC #1800 — Maximum Ascending Subarray Sum - COMPLETED - COMPLETED
- #LC #2012 — Sum of Beauty in the Array - COMPLETED - COMPLETED
These require:
- Absolute control over running state
- Edge-case maturity
- No panic resets
The ONE Rule That Wins Interviews
Always be able to answer:
“What variables am I maintaining and why?”
If you can explain that clearly,
you are ready for Pattern 2.
Common Interview Killers
- Overcomplicating simple scans
- Using extra arrays unnecessarily
- Reset logic mistakes
- Forgetting edge cases (all negatives, single element, etc.)
INTERVIEW REVISION CARD — Pattern 1
1️⃣ Pattern in One Line
"Scan the array once, maintain 1–3 running variables, build the answer incrementally."
2️⃣ Recognize It When...
- Single pass is enough
- No extra data structure needed
- You're tracking running max/min/sum/count
- Trigger words: "scan", "track", "running", "difference", "maximum/minimum"
- Constraints hint O(N) time, O(1) space
3️⃣ Don't Confuse With...
- Prefix Sum (P3) → when you need range queries
- Sliding Window (P4) → when window boundaries move dynamically
- Hashing (P2) → when you need fast lookups of past values
4️⃣ Approach in 3 Steps
- #Identify what variables to maintain (max, min, sum, count, reset trigger)
- #Define reset condition clearly — when does state restart?
- #Update answer at every step or at the end
5️⃣ Invariant to Maintain
"At every index i, my variables correctly represent the best answer for arr[0..i]."
6️⃣ Complexity to Justify
- Time: O(N) — single pass
- Space: O(1) — only variables, no extra arrays
- Why: No nested loops, no recursion, no auxiliary structures
7️⃣ Edge Cases to Always Check
- Empty array
- Single element array
- All elements same
- All elements negative
- Array of length 2
8️⃣ One Line to Say in Interview
"This is a pure traversal — I'll maintain running state variables and update the answer incrementally in O(N) time and O(1) space."
Pattern 1 is now SYSTEMATIC
After 30 problems:
You shouldn’t think
“Which pattern is this?”
You should instantly say:
“Just traversal. Maintain state.”