| Problem # | Problem Title | Link | Pseudocode Solution |
|---|---|---|---|
| 303 | Range Sum Query - Immutable | View Problem | 1. Build prefix sum array 2. For range [i,j]: return prefix[j+1] - prefix[i] |
| 525 | Contiguous Array | View Problem | 1. Use HashMap to store count differences 2. Track running sum (0→-1, 1→+1) 3. Find max distance between same sums |
| 560 | Subarray Sum Equals K | View Problem | 1. HashMap stores prefix sum frequencies 2. For each sum, check if (sum-k) exists 3. Count occurrences |
| Problem # | Problem Title | Link | Pseudocode Solution |
|---|---|---|---|
| 167 | Two Sum II - Input Array is Sorted | View Problem | 1. left = 0, right = n-1 2. If sum > target: right-- 3. If sum < target: left++ 4. Return indices when sum = target |
| 15 | 3Sum | View Problem | 1. Sort array 2. For each i, use two pointers on remaining 3. Skip duplicates 4. Find triplets with sum = 0 |
| 11 | Container With Most Water | View Problem | 1. left = 0, right = n-1 2. Calculate area = min(height[l], height[r]) * (r-l) 3. Move pointer with smaller height |
| Problem # | Problem Title | Link | Pseudocode Solution |
|---|---|---|---|
| 643 | Maximum Average Subarray I | View Problem | 1. Calculate sum of first k elements 2. Slide window: subtract left, add right 3. Track maximum sum |
| 3 | Longest Substring Without Repeating Characters | View Problem | 1. Use Set to track characters in window 2. Expand right, shrink left when duplicate 3. Track max window size |
| 76 | Minimum Window Substring | View Problem | 1. Count chars in target 2. Expand right until valid 3. Shrink left while valid 4. Track minimum window |
| Problem # | Problem Title | Link | Pseudocode Solution |
|---|---|---|---|
| 141 | Linked List Cycle | View Problem | 1. slow = head, fast = head 2. Move slow by 1, fast by 2 3. If they meet, cycle exists |
| 202 | Happy Number | View Problem | 1. slow = n, fast = n 2. slow does 1 iteration, fast does 2 3. If cycle detected, not happy |
| 287 | Find the Duplicate Number | View Problem | 1. Use array values as indices 2. Apply Floyd's cycle detection 3. Find entrance to cycle |
| Problem # | Problem Title | Link | Pseudocode Solution |
|---|---|---|---|
| 206 | Reverse Linked List | View Problem | 1. prev = null, curr = head 2. next = curr.next 3. curr.next = prev 4. prev = curr, curr = next |
| 92 | Reverse Linked List II | View Problem | 1. Find position m-1 2. Reverse m to n nodes 3. Connect reversed portion back |
| 24 | Swap Nodes in Pairs | View Problem | 1. Use dummy node 2. For each pair: adjust 4 pointers 3. prev.next = second, first.next = second.next |
| Problem # | Problem Title | Link | Pseudocode Solution |
|---|---|---|---|
| 496 | Next Greater Element I | View Problem | 1. Use stack to store elements 2. For each element, pop smaller ones 3. Top of stack is next greater |
| 739 | Daily Temperatures | View Problem | 1. Stack stores indices 2. Pop indices with smaller temps 3. Answer[i] = current_index - popped_index |
| 84 | Largest Rectangle in Histogram | View Problem | 1. Stack maintains increasing heights 2. On smaller height, calculate area 3. Width = current_i - stack.top() - 1 |
| Problem # | Problem Title | Link | Pseudocode Solution |
|---|---|---|---|
| 215 | Kth Largest Element in an Array | View Problem | 1. Use min-heap of size k 2. Add elements, remove if size > k 3. Root is kth largest |
| 347 | Top K Frequent Elements | View Problem | 1. Count frequencies 2. Use min-heap of size k 3. Compare by frequency |
| 373 | Find K Pairs with Smallest Sums | View Problem | 1. Use min-heap for pairs 2. Start with (0,0) pair 3. Add adjacent pairs to heap |
| Problem # | Problem Title | Link | Pseudocode Solution |
|---|---|---|---|
| 56 | Merge Intervals | View Problem | 1. Sort by start time 2. If current.start <= prev.end: merge 3. Else add to result |
| 57 | Insert Interval | View Problem | 1. Add non-overlapping intervals before 2. Merge overlapping intervals 3. Add remaining intervals |
| 435 | Non-overlapping Intervals | View Problem | 1. Sort by end time 2. Greedily select non-overlapping 3. Count removals needed |
| Problem # | Problem Title | Link | Pseudocode Solution |
|---|---|---|---|
| 33 | Search in Rotated Sorted Array | View Problem | 1. Find which half is sorted 2. Check if target in sorted half 3. Adjust left/right accordingly |
| 153 | Find Minimum in Rotated Sorted Array | View Problem | 1. Compare mid with right 2. If mid > right: minimum in right half 3. Else minimum in left half |
| 240 | Search a 2D Matrix II | View Problem | 1. Start from top-right corner 2. If target < current: move left 3. If target > current: move down |
| Problem # | Problem Title | Link | Pseudocode Solution |
|---|---|---|---|
| 257 | Binary Tree Paths | View Problem | 1. DFS with path string 2. If leaf: add path to result 3. Recurse on children with updated path |
| 230 | Kth Smallest Element in a BST | View Problem | 1. Inorder traversal (left, root, right) 2. Count nodes visited 3. Return when count = k |
| 124 | Binary Tree Maximum Path Sum | View Problem | 1. For each node, calculate max gain 2. Update global max with path through node 3. Return max gain from one side |
| 107 | Binary Tree Level Order Traversal II | View Problem | 1. Level order traversal with queue 2. Store each level in array 3. Reverse final result |
| Problem # | Problem Title | Link | Pseudocode Solution |
|---|---|---|---|
| 133 | Clone Graph | View Problem | 1. HashMap to store original->clone mapping 2. DFS: create clone, recurse on neighbors 3. Return cloned node |
| 113 | Path Sum II | View Problem | 1. DFS with current path and remaining sum 2. If leaf and sum=0: add path to result 3. Backtrack after exploring |
| 210 | Course Schedule II | View Problem | 1. Build adjacency list 2. DFS with 3 states: unvisited, visiting, visited 3. Detect cycles and build topological order |
| Problem # | Problem Title | Link | Pseudocode Solution |
|---|---|---|---|
| 102 | Binary Tree Level Order Traversal | View Problem | 1. Use queue starting with root 2. For each level, process all nodes 3. Add children to queue for next level |
| 994 | Rotting Oranges | View Problem | 1. Add all rotten oranges to queue 2. BFS: spread rot to adjacent fresh oranges 3. Count minutes and check if all rotten |
| 127 | Word Ladder | View Problem | 1. BFS with queue of words and distances 2. For each word, try all 1-char changes 3. Return distance when target found |
| Problem # | Problem Title | Link | Pseudocode Solution |
|---|---|---|---|
| 733 | Flood Fill | View Problem | 1. DFS/BFS from starting pixel 2. Change color if matches start color 3. Recurse/queue adjacent pixels |
| 200 | Number of Islands | View Problem | 1. Scan grid for '1's 2. DFS/BFS to mark entire island 3. Count number of islands found |
| 130 | Surrounded Regions | View Problem | 1. Mark border 'O's and connected regions 2. Flip remaining 'O's to 'X' 3. Restore marked regions |
| Problem # | Problem Title | Link | Pseudocode Solution |
|---|---|---|---|
| 46 | Permutations | View Problem | 1. Swap elements at each position 2. Recurse for next position 3. Backtrack by swapping back |
| 78 | Subsets | View Problem | 1. For each element: choose to include or not 2. Recurse with both options 3. Add to result when all elements processed |
| 51 | N-Queens | View Problem | 1. Try placing queen in each row 2. Check column and diagonal conflicts 3. Backtrack if no valid position |
| Problem # | Problem Title | Link | Pseudocode Solution |
|---|---|---|---|
| 70 | Climbing Stairs | View Problem | 1. dp[i] = dp[i-1] + dp[i-2] 2. Base cases: dp[0]=1, dp[1]=1 3. Return dp[n] |
| 322 | Coin Change | View Problem | 1. dp[i] = min coins for amount i 2. For each coin: dp[i] = min(dp[i], dp[i-coin]+1) 3. Return dp[amount] |
| 300 | Longest Increasing Subsequence | View Problem | 1. dp[i] = length of LIS ending at i 2. For each j < i: if nums[j] < nums[i], update dp[i] 3. Return max dp |
| 416 | Partition Equal Subset Sum | View Problem | 1. dp[i][j] = can sum j be formed with first i elements 2. dp[i][j] = dp[i-1][j] OR dp[i-1][j-nums[i]] 3. Return dp[n][sum/2] |
| 312 | Burst Balloons | View Problem | 1. dp[i][j] = max coins from bursting balloons i to j 2. For each k in (i,j): dp[i][j] = max(dp[i][k] + nums[i-1]*nums[k]*nums[j+1] + dp[k][j]) 3. Return dp[1][n] |
| 1143 | Longest Common Subsequence | View Problem | 1. dp[i][j] = LCS of text1[0..i] and text2[0..j] 2. If chars match: dp[i][j] = dp[i-1][j-1] + 1 3. Else: dp[i][j] = max(dp[i-1][j], dp[i][j-1]) |