Software Engineer's Blog

Showing Posts From

Easy

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.