Software Engineer's Blog

Showing Posts From

Blind 75

1143. Longest Common Subsequence

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.

647. Palindromic Substrings

Coding Interview

647. Palindromic Substrings

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.

572. Subtree of Another Tree

Coding Interview

572. Subtree of Another Tree

Jason Yang · 04 Aug, 2026

Subtree of Another Tree (LeetCode 572): anchor the match at every node and reuse Same Tree as the equality check — the clean O(m*n) recursion in Java.

435. Non-overlapping Intervals

Coding Interview

435. Non-overlapping Intervals

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.

424. Longest Repeating Character Replacement

Coding Interview

424. Longest Repeating Character Replacement

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.

417. Pacific Atlantic Water Flow

Coding Interview

417. Pacific Atlantic Water Flow

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.

371. Sum of Two Integers

Coding Interview

371. Sum of Two Integers

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.

347. Top K Frequent Elements

Coding Interview

347. Top K Frequent Elements

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.

338. Counting Bits

Coding Interview

338. Counting Bits

Jason Yang · 04 Aug, 2026

Counting Bits (LeetCode 338): why dp[i] = dp[i >> 1] + (i & 1) counts set bits in one linear pass, plus the built-in baseline it beats — in Java.

322. Coin Change

Coding Interview

322. Coin Change

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.

300. Longest Increasing Subsequence

Coding Interview

300. Longest Increasing Subsequence

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.

297. Serialize and Deserialize Binary Tree

Coding Interview

297. Serialize and Deserialize Binary Tree

Jason Yang · 04 Aug, 2026

Serialize and Deserialize Binary Tree (LeetCode 297): why a preorder walk with explicit null markers round-trips any tree, coded cleanly in Java.

295. Find Median from Data Stream

Coding Interview

295. Find Median from Data Stream

Jason Yang · 04 Aug, 2026

Find Median from Data Stream (LeetCode 295): balance a max-heap and a min-heap so the median sits at the top, with O(log n) inserts in Java.

271. Encode and Decode Strings

Coding Interview

271. Encode and Decode Strings

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.

269. Alien Dictionary

Coding Interview

269. Alien Dictionary

Jason Yang · 04 Aug, 2026

Alien Dictionary (LeetCode 269): turn a sorted word list into a character graph, then topologically sort it with Kahn's BFS in Java — cycles and prefixes included.

268. Missing Number

Coding Interview

268. Missing Number

Jason Yang · 04 Aug, 2026

Missing Number (LeetCode 268): why XOR-ing every index with every value leaves exactly the missing one, plus the Gauss-sum alternative, in Java.

261. Graph Valid Tree

Coding Interview

261. Graph Valid Tree

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.

253. Meeting Rooms II

Coding Interview

253. Meeting Rooms II

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.

252. Meeting Rooms

Coding Interview

252. Meeting Rooms

Jason Yang · 04 Aug, 2026

Meeting Rooms (LeetCode 252): sort intervals by start, then one pass reveals whether any two overlap. Java code, the strict-vs-equal trap, and complexity.

242. Valid Anagram

Coding Interview

242. Valid Anagram

Jason Yang · 04 Aug, 2026

Valid Anagram (LeetCode 242): why a 26-slot frequency count beats sorting, the one-array Java solution, and how the Unicode follow-up changes the answer.

230. Kth Smallest Element in a BST

Coding Interview

230. Kth Smallest Element in a BST

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.

226. Invert Binary Tree

Coding Interview

226. Invert Binary Tree

Jason Yang · 04 Aug, 2026

Invert Binary Tree (LeetCode 226): swap every node's children with a three-line recursion, plus the iterative BFS version and the null base case that matters.

212. Word Search II

Coding Interview

212. Word Search II

Jason Yang · 04 Aug, 2026

Word Search II (LeetCode 212): why one shared Trie beats running Word Search once per word, plus the backtracking DFS and pruning tricks, in Java.

211. Design Add and Search Words Data Structure

Coding Interview

211. Design Add and Search Words Data Structure

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.

208. Implement Trie (Prefix Tree)

Coding Interview

208. Implement Trie (Prefix Tree)

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).

207. Course Schedule

Coding Interview

207. Course Schedule

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.

206. Reverse Linked List

Coding Interview

206. Reverse Linked List

Jason Yang · 04 Aug, 2026

Reverse Linked List (LeetCode 206): the three-pointer flip that reverses a singly linked list in place, plus the recursive version and why order matters.

200. Number of Islands

Coding Interview

200. Number of Islands

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.

191. Number of 1 Bits

Coding Interview

191. Number of 1 Bits

Jason Yang · 04 Aug, 2026

Number of 1 Bits (LeetCode 191): counting set bits with a plain shift loop, then Brian Kernighan's n & (n-1) trick that only loops once per set bit — in Java.

190. Reverse Bits

Coding Interview

190. Reverse Bits

Jason Yang · 04 Aug, 2026

Reverse Bits (LeetCode 190): peel the low bit, stack it onto the result 32 times, and the >>> vs >> shift nuance in Java. Plus the byte-cache follow-up.

143. Reorder List

Coding Interview

143. Reorder List

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.

141. Linked List Cycle

Coding Interview

141. Linked List Cycle

Jason Yang · 04 Aug, 2026

Linked List Cycle (LeetCode 141): why two pointers moving at different speeds must collide inside a loop, and the O(1)-space Floyd's algorithm in Java.

139. Word Break

Coding Interview

139. Word Break

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.

133. Clone Graph

Coding Interview

133. Clone Graph

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.

124. Binary Tree Maximum Path Sum

Coding Interview

124. Binary Tree Maximum Path Sum

Jason Yang · 04 Aug, 2026

Binary Tree Maximum Path Sum (LeetCode 124): why one DFS returns a single-branch gain to the parent while tracking a global best that bends through a node.

104. Maximum Depth of Binary Tree

Coding Interview

104. Maximum Depth of Binary Tree

Jason Yang · 04 Aug, 2026

Maximum Depth of Binary Tree (LeetCode 104): the one-line DFS recurrence, why depth is 1 + the taller subtree, and a BFS alternative in Java.

102. Binary Tree Level Order Traversal

Coding Interview

102. Binary Tree Level Order Traversal

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.

100. Same Tree

Coding Interview

100. Same Tree

Jason Yang · 04 Aug, 2026

Same Tree (LeetCode 100): compare two binary trees for identical shape and values with a four-line recursion, plus the iterative queue version and its traps.

98. Validate Binary Search Tree

Coding Interview

98. Validate Binary Search Tree

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.

91. Decode Ways

Coding Interview

91. Decode Ways

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.

79. Word Search

Coding Interview

79. Word Search

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.

73. Set Matrix Zeroes

Coding Interview

73. Set Matrix Zeroes

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.

62. Unique Paths

Coding Interview

62. Unique Paths

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.

57. Insert Interval

Coding Interview

57. Insert Interval

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.

56. Merge Intervals

Coding Interview

56. Merge Intervals

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.

55. Jump Game

Coding Interview

55. Jump Game

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.

54. Spiral Matrix

Coding Interview

54. Spiral Matrix

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.

49. Group Anagrams

Coding Interview

49. Group Anagrams

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.

48. Rotate Image

Coding Interview

48. Rotate Image

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.

39. Combination Sum

Coding Interview

39. Combination Sum

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.

23. Merge k Sorted Lists

Coding Interview

23. Merge k Sorted Lists

Jason Yang · 04 Aug, 2026

Merge k Sorted Lists (LeetCode 23): why merging one list at a time is O(n·k), and how a min-heap or pairwise merging cuts it to O(n log k) in Java.

21. Merge Two Sorted Lists

Coding Interview

21. Merge Two Sorted Lists

Jason Yang · 04 Aug, 2026

Merge Two Sorted Lists (LeetCode 21): the dummy-head trick that removes every empty-list special case, plus the O(1)-space splice solution in Java.

20. Valid Parentheses

Coding Interview

20. Valid Parentheses

Jason Yang · 04 Aug, 2026

Valid Parentheses (LeetCode 20): why a stack is the natural fit for matching brackets, a clean Java solution, and the empty-stack edge cases interviewers probe.

19. Remove Nth Node From End of List

Coding Interview

19. Remove Nth Node From End of List

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.

5. Longest Palindromic Substring

Coding Interview

5. Longest Palindromic Substring

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.

213. House Robber II

Coding Interview

213. House Robber II

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.

198. House Robber

Coding Interview

198. House Robber

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.

70. Climbing Stairs

Coding Interview

70. Climbing Stairs

Jason Yang · 04 Aug, 2026

Climbing Stairs (LeetCode 70): why the answer is Fibonacci, the memoized and bottom-up solutions in Java, and the rolling trick that drops it to O(1) space.

76. Minimum Window Substring

Coding Interview

76. Minimum Window Substring

Jason Yang · 31 Mar, 2026

Minimum Window Substring (LeetCode 76): the sliding-window O(n) approach with character counts to shrink to the smallest valid window, with a visual.

3. Longest Substring Without Repeating Characters

Coding Interview

3. Longest Substring Without Repeating Characters

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.

125. Valid Palindrome

Coding Interview

125. Valid Palindrome

Jason Yang · 31 Mar, 2026

Valid Palindrome (LeetCode 125): the two-pointer O(n) check that skips non-alphanumerics in place, why it beats building a cleaned string, and the edge cases.

128. Longest Consecutive Sequence

Coding Interview

128. Longest Consecutive Sequence

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.

15. 3Sum

Coding Interview

15. 3Sum

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.

11. Container With Most Water

Coding Interview

11. Container With Most Water

Jason Yang · 27 Mar, 2026

Container With Most Water (LeetCode 11): the two-pointer O(n) approach, and the short proof for why moving the shorter line never skips a better answer — with an interactive visualization.

33. Search in Rotated Sorted Array

Coding Interview

33. Search in Rotated Sorted Array

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.

153. Find Minimum in Rotated Sorted Array

Coding Interview

153. Find Minimum in Rotated Sorted Array

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.

152. Maximum Product Subarray

Coding Interview

152. Maximum Product Subarray

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.

53. Maximum Subarray

Coding Interview

53. Maximum Subarray

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.

238. Product of Array Except Self

Coding Interview

238. Product of Array Except Self

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.

217. Contains Duplicate

Coding Interview

217. Contains Duplicate

Jason Yang · 27 Nov, 2025

Contains Duplicate (LeetCode 217): compare the brute-force, sorting, and hash-set approaches — and why 'just use a hash set' isn't always the right reflex.

121. Best Time to Buy and Sell Stock

Coding Interview

121. Best Time to Buy and Sell Stock

Jason Yang · 26 Nov, 2025

Best Time to Buy and Sell Stock (LeetCode 121): the single-pass O(n) solution that tracks the lowest price so far, with an interactive step-by-step visual.

1. Two Sum

Coding Interview

1. Two Sum

Jason Yang · 11 Nov, 2025

Two Sum (LeetCode 1) two ways: the brute-force O(n^2) scan vs the hash-map O(n) approach — with the intuition, edge cases, and the space-time trade-off.