Problem-Solving Framework & Approach
š Concept
Having a systematic approach to solving problems is MORE important than knowing every algorithm. Top engineers and competitive programmers follow a framework ā not random guessing.
The UMPIRE Method (Interview Framework):
- Understand the problem ā Read carefully. Ask clarifying questions. What are the inputs? Outputs? Constraints?
- Match to known patterns ā Is this a sliding window? Two pointers? DP? Graph problem?
- Plan your approach ā Write pseudocode. Discuss time/space complexity BEFORE coding.
- Implement ā Write clean, modular code. Use helper functions.
- Review ā Walk through with an example. Check edge cases.
- Evaluate ā Analyze complexity. Can you optimize?
Pattern Recognition ā The Key Skill:
- "Find subarray with property X" ā Sliding window or prefix sum
- "Find pair with property X" ā Two pointers (sorted) or hash map
- "Find optimal/count/can you" ā Dynamic programming
- "Generate all possibilities" ā Backtracking
- "Connected components" ā Graph BFS/DFS or Union-Find
- "Sorted data, find target" ā Binary search
- "Top K elements" ā Heap
- "String prefix matching" ā Trie
Constraint-based complexity selection:
- n ⤠10: O(n!) ā brute force, permutations OK
- n ⤠20: O(2āæ) ā bitmask DP, subsets
- n ⤠500: O(n³) ā 3 nested loops OK
- n ⤠5,000: O(n²) ā 2 nested loops OK
- n ⤠10ā¶: O(n log n) ā sorting OK, but not O(n²)
- n ⤠10āø: O(n) ā single pass required
- n > 10āø: O(log n) or O(1) ā binary search or math
š Real-world analogy: A doctor doesn't randomly prescribe medicine. They: 1) Listen to symptoms (understand), 2) Match to known conditions (pattern), 3) Decide treatment (plan), 4) Prescribe/operate (implement), 5) Follow up (review). Same process.
š» Code Example
1// EXAMPLE: Solve "Two Sum" using the framework23// Step 1: UNDERSTAND4// Given: array of numbers, target sum5// Find: indices of two numbers that add to target6// Constraints: exactly one solution, can't use same element twice78// Step 2: MATCH PATTERN9// "Find pair" ā hash map (store complement)1011// Step 3: PLAN12// For each number, check if (target - number) exists in map13// If yes ā return both indices14// If no ā add current number to map1516// Step 4: IMPLEMENT17function twoSum(nums: number[], target: number): [number, number] {18 const map = new Map<number, number>(); // value ā index1920 for (let i = 0; i < nums.length; i++) {21 const complement = target - nums[i];22 if (map.has(complement)) {23 return [map.get(complement)!, i];24 }25 map.set(nums[i], i);26 }2728 throw new Error("No solution found");29}3031// Step 5: REVIEW ā trace with example32// nums = [2, 7, 11, 15], target = 933// i=0: complement=7, map={}, add 2ā0, map={2:0}34// i=1: complement=2, map={2:0} ā FOUND! return [0, 1] ā3536// Step 6: EVALUATE37// Time: O(n) ā single pass38// Space: O(n) ā hash map39// Better than O(n²) brute force!4041// CONSTRAINT-BASED APPROACH EXAMPLE42function solveProblem(n: number): string {43 if (n <= 20) return "Can use O(2^n) ā bitmask/subset DP";44 if (n <= 500) return "Can use O(n³) ā 3 nested loops";45 if (n <= 5000) return "Can use O(n²) ā 2 nested loops";46 if (n <= 1e6) return "Need O(n log n) ā sorting-based";47 if (n <= 1e8) return "Need O(n) ā single pass";48 return "Need O(log n) or O(1) ā binary search or math";49}5051// PATTERN MATCHING EXAMPLES52// "Maximum subarray sum" ā Kadane's algorithm (DP)53function maxSubarraySum(arr: number[]): number {54 let maxSoFar = arr[0];55 let maxEndingHere = arr[0];56 for (let i = 1; i < arr.length; i++) {57 maxEndingHere = Math.max(arr[i], maxEndingHere + arr[i]);58 maxSoFar = Math.max(maxSoFar, maxEndingHere);59 }60 return maxSoFar;61}6263// "Find if path exists" ā BFS/DFS64function hasPath(graph: Map<number, number[]>, start: number, end: number): boolean {65 const visited = new Set<number>();66 const queue = [start];67 while (queue.length) {68 const node = queue.shift()!;69 if (node === end) return true;70 if (visited.has(node)) continue;71 visited.add(node);72 for (const neighbor of graph.get(node) || []) {73 queue.push(neighbor);74 }75 }76 return false;77}
šļø Practice Exercise
Practice Problems:
- Using UMPIRE, solve: "Find the longest substring without repeating characters"
- Given n = 10,000, what's the maximum acceptable time complexity?
- Match each problem to a pattern:
- "Find shortest path in unweighted graph" ā ?
- "Find maximum sum subarray" ā ?
- "Check if string matches pattern" ā ?
- Walk through solving "Valid Parentheses" step-by-step with the framework
- Given constraint n ⤠10āµ, would O(n²) solution pass? (assume 10āø ops/sec)
- Practice explaining your approach BEFORE writing code for 3 problems
- Solve a problem you've never seen ā document your thinking process
- Take a brute force O(n³) solution and optimize it step by step to O(n)
- For a problem with multiple possible approaches, compare trade-offs
- Simulate a 45-min interview: 5 min understand, 10 min plan, 20 min code, 10 min review
ā ļø Common Mistakes
Jumping into coding without understanding the problem ā you WILL solve the wrong problem
Not asking clarifying questions in interviews ā interviewers EXPECT you to ask about edge cases, constraints, and assumptions
Trying to find the optimal solution immediately ā start with brute force, then optimize
Not considering constraints to determine acceptable complexity ā n ⤠1000 means O(n²) is fine
Memorizing solutions instead of understanding patterns ā you'll fail on any variation you haven't seen
š¼ Interview Questions
š¤ Mock Interview
Practice a live interview for Problem-Solving Framework & Approach