Coding Interview
1143. Longest Common Subsequence
Jason Yang · 04 Aug, 2026
Longest Common Subsequence (LeetCode 1143): the match-or-drop grid recurrence, why the DP table is 2D, and a rolling O(min(m,n))-space solution in Java.
Showing Posts From
Coding Interview
Jason Yang · 04 Aug, 2026
Longest Common Subsequence (LeetCode 1143): the match-or-drop grid recurrence, why the DP table is 2D, and a rolling O(min(m,n))-space solution in Java.
Coding Interview
Jason Yang · 04 Aug, 2026
Palindromic Substrings (LeetCode 647): count every palindrome by expanding around each center for O(n^2) time and O(1) space in Java, plus the DP alternative.
Coding Interview
Jason Yang · 04 Aug, 2026
Non-overlapping Intervals (LeetCode 435): sort by end time and greedily keep the earliest-finishing intervals, so the fewest removals fall out for free.
Coding Interview
Jason Yang · 04 Aug, 2026
Longest Repeating Character Replacement (LeetCode 424): why a window is valid when its length minus its most-frequent letter stays within k, solved in Java.
Coding Interview
Jason Yang · 04 Aug, 2026
Pacific Atlantic Water Flow (LeetCode 417): flip the flow and DFS inward from each ocean's border, then intersect the two reachable sets. Java solution.
Coding Interview
Jason Yang · 04 Aug, 2026
Sum of Two Integers (LeetCode 371): add two numbers using only XOR and AND. Here's why XOR is the sum, AND is the carry, and how the loop lands in Java.
Coding Interview
Jason Yang · 04 Aug, 2026
Top K Frequent Elements (LeetCode 347): count with a hash map, then beat the O(n log n) bound by bucketing values by frequency for an O(n) answer in Java.
Coding Interview
Jason Yang · 04 Aug, 2026
Number of Connected Components (LeetCode 323) in Java: count merges instead of nodes with Union-Find, or flood-fill each unvisited node with DFS.
Coding Interview
Jason Yang · 04 Aug, 2026
Coin Change (LeetCode 322): why grabbing the biggest coin fails, and the bottom-up DP that finds the fewest coins for an amount in O(amount × coins) — in Java.
Coding Interview
Jason Yang · 04 Aug, 2026
Longest Increasing Subsequence (LeetCode 300): the O(n^2) DP for the intuition, then the O(n log n) patience-sorting trick with binary search, in Java.
Coding Interview
Jason Yang · 04 Aug, 2026
Encode and Decode Strings (LeetCode 271): why a delimiter alone can't work, and the length-prefix codec that round-trips any characters in Java.
Coding Interview
Jason Yang · 04 Aug, 2026
Graph Valid Tree (LeetCode 261): a tree is a connected, acyclic graph with exactly n-1 edges — solve it with union-find cycle detection in Java.
Coding Interview
Jason Yang · 04 Aug, 2026
Meeting Rooms II (LeetCode 253): find the minimum rooms by tracking peak overlap — the min-heap solution and the sweep-line trick, both in Java.
Coding Interview
Jason Yang · 04 Aug, 2026
Lowest Common Ancestor of a BST (LeetCode 235): use the sorted-order property to walk down until the two targets split, an O(h) one-pass solution in Java.
Coding Interview
Jason Yang · 04 Aug, 2026
Kth Smallest Element in a BST (LeetCode 230): why an inorder walk visits values in sorted order, so the kth node you touch is the answer — solved in Java.
Coding Interview
Jason Yang · 04 Aug, 2026
Design Add and Search Words (LeetCode 211): store words in a trie, then DFS through it so a '.' wildcard can branch into every child. Java solution explained.
Coding Interview
Jason Yang · 04 Aug, 2026
Implement Trie (LeetCode 208): build a prefix tree in Java where each node branches 26 ways, so insert, search, and startsWith all run in O(word length).
Coding Interview
Jason Yang · 04 Aug, 2026
Course Schedule (LeetCode 207): the whole problem is 'does this directed graph have a cycle?' Solve it with Kahn's topological sort in Java, plus the DFS alternative.
Coding Interview
Jason Yang · 04 Aug, 2026
Number of Islands (LeetCode 200): count connected land groups with a DFS flood fill that sinks each island as it's found, in clean idiomatic Java.
Coding Interview
Jason Yang · 04 Aug, 2026
Reorder List (LeetCode 143): interleave a linked list front-to-back in O(1) space by combining three classic pointer moves — find the middle, reverse, merge.
Coding Interview
Jason Yang · 04 Aug, 2026
Word Break (LeetCode 139): why a greedy longest-match fails, how prefix DP with dp[i] = 'is s[0..i) segmentable' fixes it, and the prefix-DP Java solution.
Coding Interview
Jason Yang · 04 Aug, 2026
Clone Graph (LeetCode 133): why a single HashMap from original to copy solves cycles and shared neighbors at once, with a clean DFS solution in Java.
Coding Interview
Jason Yang · 04 Aug, 2026
Construct Binary Tree from Preorder and Inorder Traversal (LeetCode 105): why preorder hands you the root and inorder splits left from right, in O(n) Java.
Coding Interview
Jason Yang · 04 Aug, 2026
Binary Tree Level Order Traversal (LeetCode 102): the queue-based BFS, why snapshotting the queue size groups each level, and clean Java code.
Coding Interview
Jason Yang · 04 Aug, 2026
Validate Binary Search Tree (LeetCode 98): why checking a node against its children fails, and the min/max bounds recursion that fixes it in Java.
Coding Interview
Jason Yang · 04 Aug, 2026
Decode Ways (LeetCode 91): the Fibonacci-shaped count recurrence, why leading zeros kill a decoding, and the clean O(1)-space DP in Java.
Coding Interview
Jason Yang · 04 Aug, 2026
Word Search (LeetCode 79): how DFS plus in-place marking walks the grid, why you restore each cell on the way out, and the clean Java backtracking solution.
Coding Interview
Jason Yang · 04 Aug, 2026
Set Matrix Zeroes (LeetCode 73): why an in-place mark-then-sweep needs the matrix's own first row and column as scratch, plus the O(1)-space Java code.
Coding Interview
Jason Yang · 04 Aug, 2026
Unique Paths (LeetCode 62): why each grid cell is the sum of the ways from above and from the left, plus the O(n)-space rolling DP solution in Java.
Coding Interview
Jason Yang · 04 Aug, 2026
Insert Interval (LeetCode 57): why an already-sorted list lets you insert in one linear pass — the before / merge / after sweep in Java, no sorting needed.
Coding Interview
Jason Yang · 04 Aug, 2026
Merge Intervals (LeetCode 56): sort by start, then sweep once and extend the last interval whenever the next one overlaps — the Java sort-and-merge template.
Coding Interview
Jason Yang · 04 Aug, 2026
Jump Game (LeetCode 55): why one greedy pass tracking the farthest reachable index beats the O(n^2) DP, and why a trailing zero is the real trap, in Java.
Coding Interview
Jason Yang · 04 Aug, 2026
Spiral Matrix (LeetCode 54): walk the grid clockwise by tracking four edges and peeling one row or column off after each pass — clean Java, no visited set.
Coding Interview
Jason Yang · 04 Aug, 2026
Group Anagrams (LeetCode 49): pick a canonical key so every anagram hashes to the same bucket. Sorted-key vs count-array key in Java, with complexity.
Coding Interview
Jason Yang · 04 Aug, 2026
Rotate Image (LeetCode 48): why transpose-then-reverse rotates a matrix 90° clockwise in place, with the O(1)-space Java solution and the index math behind it.
Coding Interview
Jason Yang · 04 Aug, 2026
Combination Sum (LeetCode 39): why passing the same start index lets you reuse numbers, plus a sorted-and-pruned backtracking solution in Java.
Coding Interview
Jason Yang · 04 Aug, 2026
Remove Nth Node From End of List (LeetCode 19): why a two-pointer gap lets you delete the nth-from-last node in one pass, plus the dummy-head trick in Java.
Coding Interview
Jason Yang · 04 Aug, 2026
Longest Palindromic Substring (LeetCode 5): why expanding around each center beats the DP table, the two-center trick for even lengths, and clean Java.
Coding Interview
Jason Yang · 04 Aug, 2026
House Robber II (LeetCode 213): the circular twist solved by running the linear House Robber twice — once excluding the first house, once the last — in Java.
Coding Interview
Jason Yang · 04 Aug, 2026
House Robber (LeetCode 198): the take-or-skip recurrence, why you can't rob adjacent houses, and the O(1)-space rolling solution in Java.
Coding Interview
Jason Yang · 31 Mar, 2026
Longest Substring Without Repeating Characters (LeetCode 3): the sliding-window O(n) approach, and why the int[128] version can jump the left pointer instead of stepping — with interactive visuals.
Coding Interview
Jason Yang · 30 Mar, 2026
Longest Consecutive Sequence (LeetCode 128): the hash-set O(n) trick that only counts from sequence starts, with an interactive step-by-step visual.
Coding Interview
Jason Yang · 27 Mar, 2026
3Sum (LeetCode 15): sort then two-pointer for an O(n^2) solution, why sorting unlocks it, and the three places duplicate triplets sneak in — with an interactive visualization.
Coding Interview
Jason Yang · 03 Dec, 2025
Search in Rotated Sorted Array (LeetCode 33): a modified O(log n) binary search that finds which half is sorted, with an interactive step visual.
Coding Interview
Jason Yang · 02 Dec, 2025
Find Minimum in Rotated Sorted Array (LeetCode 153): the O(log n) binary search that locates the rotation pivot, explained step by step with examples.
Coding Interview
Jason Yang · 01 Dec, 2025
Maximum Product Subarray (LeetCode 152): why you track max and min together to handle negatives and zeros, and the O(n) dynamic-programming solution.
Coding Interview
Jason Yang · 29 Nov, 2025
Maximum Subarray (LeetCode 53): Kadane's algorithm explained as one decision — extend or restart — plus the O(n) to O(1) space drop and a full worked trace.
Coding Interview
Jason Yang · 28 Nov, 2025
Product of Array Except Self (LeetCode 238): the prefix and suffix product trick that avoids division for an O(n) solution, with an interactive visual.