Binary Tree Max Path Sum: the recursive function returns node + max(left, right) to the parent, but tracks maxSum with node + left + right. two separate concerns. the path can turn at a node but canโt extend after turning. [-10,9,20,15,7] โ 42, not 34. https://t.co/IsbwzXN2Uj
Sort Colors trips most people on one thing: after swapping with blue, don't advance white. that element is unexamined. after swapping with red, advance both. it was already a 1. that's the Dutch National Flag algorithm. Apple, Google, Meta ask this. https://t.co/CogXacs5fk
Longest Palindromic Substring trips people on one thing: odd vs even palindromes. 'cbbd' โ 'bb' requires the even-center check (expandAround i, i+1). only checking single chars gives you 'c', which is wrong. two expand calls per index, not one. https://t.co/GAvDWJUe4w
Combination Sum is the problem where backtracking clicks. add, recurse, pop. passing `start = i` not `i + 1` in the recursive call is what makes it combinations not permutations. without it, [2,3] and [3,2] both show up. https://t.co/jtJCOYmcx3
Swap Nodes in Pairs: the pointer update order matters. https://t.co/FFGowxKs6U = second, then https://t.co/KBn6NfVfkB = https://t.co/0oYiuT3YAw, then https://t.co/0oYiuT3YAw = first. Flip any two and you lose the rest of the list. And return https://t.co/yiwnktd47z, not head. head isnโt first anymore. https://t.co/4XwruTB4ed
Most people compare nums[mid] with nums[left] for Find Min in Rotated Sorted Array. Gets messy for the unrotated case. Compare with nums[right]: if mid > right, min is in the right half. Otherwise at mid or left. O(log n), no special cases. https://t.co/4dEDV6WtrP
Word Search is Number of Islands + one thing: reset the cell after DFS. that line IS the backtracking. skip it and dead-end paths permanently block valid ones. ABCB fails exactly because of this. Amazon, Bloomberg, Apple ask it constantly. https://t.co/7ZRekoFYEK
Maximum Product Subarray is Kadane's with a catch. track a running max AND a running min. negative numbers flip signs, so your minimum can become your maximum. [-2, 3, -4]: min at index 1 is -6, multiply by -4 and you get 24. https://t.co/mrkITU89Tu
Phone keypad letter combinations. The complexity is O(4^n) not O(3^n) because digits 7 and 9 have four letters, not three. Easy to get wrong in an interview. Also: return [] for empty input, not a list with an empty string. Apple asks this 24 times in recent data. https://t.co/xnT3sSpHkn
Phone keypad letter combinations. The complexity is O(4^n) not O(3^n) because digits 7 and 9 have four letters, not three. Easy to get wrong in an interview. Also: return [] for empty input, not a list with an empty string. Apple asks this 24 times in recent data. https://t.co/xnT3sSpHkn
Most people think merging two sorted linked lists needs O(n) extra space. it doesn't. you splice existing nodes by redirecting pointers, no new allocations. dummy node, compare heads, attach smaller, advance. Google, Meta, Amazon, Adobe all ask this. https://t.co/g2256oJwP1
Insert Interval is O(n) not O(n log n) because the input is pre-sorted. three cases: before (pass through), overlap (expand), after (output insert, swap current in). that swap is why out.add(insert) always works at the end. https://t.co/wOqkGUc52U
Spiral Matrix clicks once you see it as ring peeling. four pointers (top, bottom, left, right), shrink inward each loop. the bug: no boundary check before the bottom row traversal means double-counting on rectangular matrices. draw it on paper first. https://t.co/61BzyeaxbY
Rotate Image: transpose then reverse each row = 90 degrees clockwise, O(1) space. One trap: in the transpose loop, j starts at i, not 0. Start at 0 and every pair swaps twice, matrix ends up unchanged. Easy to miss. Google, Meta, Amazon ask this. https://t.co/frDghAAvXx
Majority Element II: at most 2 elements can exceed n/3 (pigeonhole). track 2 Boyer-Moore candidates instead of 1. cancellation eliminates triplets. second pass verifies. O(n), O(1). Adobe asks this constantly. https://t.co/Lby8MYFZjZ
Most people dp-table Unique Paths. works fine. but you can also use combinatorics: m+n-2 total moves, exactly m-1 go down. that's C(m+n-2, m-1). O(m+n), no table, no iteration. breaks with obstacles, but clean for the base case. https://t.co/HXY4Y8HjxC
Valid Anagram is where interviewers find out if you know the 26-int array trick. HashMap works but `c - 'a'` to map chars to indices, +1 for s, -1 for t, check all zeros is cleaner. O(1) space. Google, Bloomberg, Adobe all ask this. https://t.co/cfY7xA3iE1
Bottom-up level order traversal is just BFS + reverse. One catch: enqueue the right child BEFORE the left child. Miss that, each level in your reversed output reads right-to-left instead of left-to-right. Microsoft, Amazon, Apple ask this. https://t.co/lYZUNTtzVg
Jump Game: track maxReach (farthest reachable index so far). if current index > maxReach, you're stranded, return false. update maxReach = max(maxReach, i + nums[i]). that's it. one pass, O(n) time, O(1) space. Amazon, Google, Meta all ask this. https://t.co/xPVf4k530b
Group Anagrams clicks when you find the canonical form. "eat", "tea", "ate" all sort to "aet". that's your hash map key. group by it. the lesson: any equivalence problem has a canonical form hiding in it. asked at Amazon, Google, Meta. https://t.co/617UHuZY9D