Software Engineer's Blog

Showing Posts From

Medium

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.