DSA & Algorithms
Algorithm Paradigms & Problem-Solving Patterns
Algorithmic patterns are reusable problem-solving blueprints. Mastering fundamental paradigms allows you to systematically decompose complex engineering problems.
Track Curriculum
Subtopics & Modules
Two Pointers Technique
Opposite direction pointers, fast & slow pointers, 3Sum, and palindrome validation.
Sliding Window Pattern
Fixed vs variable length windows, maximum subarray sum, and longest substring problems.
Dynamic Programming
Memoization (top-down), tabulation (bottom-up), knapsack variations, and state transitions.
Greedy Algorithms
Local optimal choice, activity selection, Huffman coding, and fractional knapsack.
Backtracking & Recursion
State space trees, N-Queens, Sudoku solver, subsets, permutations, and pruning.
Sorting & Searching Algorithms
QuickSort, MergeSort, HeapSort, Counting Sort, and Binary Search variants.
Binary Search & Search Spaces
Binary search on answers, lower/upper bounds, rotated sorted arrays, and search space reduction.
Bit Manipulation
AND, OR, XOR, NOT operations, bitwise masks, Single Number problem, and power of two checks.
Advanced Graph Algorithms
Dijkstra's shortest path, Bellman-Ford, Kruskal's & Prim's MST, and Floyd-Warshall.
Interview Questions by Module Topic
Select a module to view its related questions, or explore all modules organized by seniority level
Two Pointers Technique
On an unsorted array, finding two numbers that sum to target requires either nested loops ($O(n^2)$) or a hash set ($O(n)$ space). However, if the array is **already sorted**, the **Two Pointers Converging Pattern** solves the problem in strict **O(n) time and O(1) auxiliary space**: 1. Initialize `left = 0` (smallest element) and `right = n - 1` (largest element). 2. Calculate current sum: `currentSum = arr[left] + arr[right]`. 3. **Decision Logic**: - If `currentSum == target`: Solution found! - If `currentSum < target`: The sum is too small. Because `arr` is sorted, incrementing `left` (`left++`) increases the sum towards the target. - If `currentSum > target`: The sum is too large. Decrementing `right` (`right--`) decreases the sum towards the target. Because the pointers only move toward each other, each step eliminates an entire row or column of potential pairs without inspection, inspecting at most N elements total.
export function twoSumSorted(numbers: number[], target: number): [number, number] | null {
let left = 0;
let right = numbers.length - 1;
while (left < right) {
const sum = numbers[left] + numbers[right];
if (sum === target) {
return [left + 1, right + 1]; // 1-indexed return
} else if (sum < target) {
left++;
} else {
right--;
}
}
return null;
}🔍 Code Mechanics (TypeScript): Monotonicity allows the algorithm to safely discard half of remaining search candidates on every single comparison.