Working through Cracking the Coding Interview (6th ed.) to sharpen CS fundamentals while exploring how to effectively collaborate with AI on technical problems.
Each problem includes at least one test suite and, where interesting, multiple implementations compared by time/space complexity.
1.1 — Is Unique: Implemented two ways. The obvious approach builds a set: O(n) time, O(n) space. The better approach uses a single integer as a bit vector — each character maps to a bit position via its ASCII value, so the "seen" tracker never grows beyond a fixed size regardless of input length: O(n) time, O(1) space.
1.5 — One Away: First pass used Counter to diff character frequencies — clean but O(n) extra space. Refactored to a two-pointer approach that handles insert/delete/replace in a single pass with O(1) space.
2.2 — Return Kth to Last: Compared two-pass (measure length, then walk) against two-pointer (leader/follower with k-node gap). Both are O(n)/O(1) — benchmarks showed the two-pointer approach is ~20% faster in practice since it makes one pass instead of two.
2.3 — Delete Middle Node: The constraint is you only have a reference to the node itself, not the previous one. The trick is to copy the next node's value into the current node and skip over it — no traversal needed.
3.1 — Three in One: Implemented twice. First version uses three independent arrays (straightforward). Second uses a single flat array divided into fixed-size sections, with a sizes array tracking fill level per stack — closer to what you'd use if memory layout mattered.
3.2 — Stack Min: O(1) min via a parallel min-stack that records the running minimum at each push. Pop from both stacks together to keep them in sync.
Python (Chapter 1)
cd chapter_01
pytestRuby (Chapters 2–3)
cd chapter_02 # or chapter_03
bundle exec rspec