A repeatable workflow for DSA problems: understand constraints → brute force → optimize with a pattern → state complexity → code and test edge cases.
Steps
- Read n, value ranges, time limits—fixed array or streaming?
- Sketch brute force and its Big-O
- Match pattern: two pointers, binary search, hash map, BFS, DP table, etc.
- Implement with clear invariants; use STL when allowed
- Test: empty, single element, duplicates, max n
Pattern cheat sheet (preview)
| Clue | Pattern |
|---|---|
| Sorted array, pair sum | Two pointers / binary search |
| Subarray with constraint | Sliding window / prefix sums |
| Fast lookup by value | Hash map |
| Shortest path unweighted | BFS |
| Overlapping subproblems | Dynamic programming |
Workflow demo: max in array
#include
#include
int main() {
std::vector a = {4, 9, 2, 7};
int best = a[0];
for (int x : a) if (x > best) best = x;
std::cout << "max = " << best << " (O(n) scan)\n";
return 0;
}
Next modules
Module 02 covers Big-O; modules 03–06 cover structures and algorithms; module 07 prepares interviews and links to AI intro.
Important interview questions and answers
- Q: Why brute force first?
A: Establishes correctness and a baseline to beat—interviewers expect you to reason before optimizing. - Q: What are edge cases?
A: Empty input, one element, duplicates, overflow ranges—often where bugs hide.
Self-check
- List four steps in the DSA workflow.
- Which pattern fits 'sorted array, find pair with sum k'?
Challenge
Trace one problem through the workflow
- Pick a LeetCode easy.
- Write brute force Big-O, then the optimizing pattern.
Done when: you can name brute force, optimized pattern, and complexity.
Interview prep
- Workflow steps?
Understand constraints → brute force → optimize pattern → state complexity → test edges.
- Sorted pair sum?
Two pointers or binary search after sort—not always hash map.