Floyd's Tortoise and Hare: Linked List Cycle Detection in Java, With the Proof

“Detect a cycle in a linked list.” Everyone recites it: slow moves one step, fast moves two, if they meet there’s a cycle. Then the interviewer says “why can’t fast skip over slow?” and the room goes quiet. Then “find where the cycle starts” — and the memorized answer runs out. Floyd’s tortoise and hare is a two-minute algorithm with a twenty-minute understanding. Here’s the understanding. The shallow answer (and why interviewers hate it) The HashSet version works and every candidate knows it: ...

2026-10-17 · 6 min · Ramesh

HashMap Internals: The Questions That Expose Shallow Knowledge

“How does HashMap work?” opens half of all Java interviews. Most candidates answer “array of linked lists, O(1) lookup” — and then the follow-ups start, and the room gets quiet. The interviewers aren’t testing whether you’ve memorized the structure. They’re testing whether you know why it’s built the way it is. Here are the questions that expose shallow knowledge, with the answers that don’t. Question 1: Why does HashMap mangle your hashCode? Everyone knows hashCode() feeds the map. Almost nobody asks what HashMap does to it first: ...

2026-10-13 · 8 min · Ramesh

The Two-Pointer Playbook: 5 Patterns, One Technique, Almost Zero Extra Space

Two pointers is the highest-ROI technique in coding interviews. The entire playbook is one idea: two indices walk through the data, and at each step a decision rule tells you which one moves. No extra arrays — O(1) extra space in nearly every pattern, usually O(n) time. Interviewers love it because it tests whether you can discard search space, not just whether you can code. Five patterns cover nearly every two-pointer question you’ll meet. Learn the decision rule for each, not just the code. (One honest exception up front: the sliding-window pattern trades O(alphabet) space for its single pass — the cheat sheet says so. Everything else is O(1).) ...

2026-10-09 · 7 min · Ramesh

Top-K Everything: Heap Questions That Actually Show Up in Java Interviews

“Find the k largest elements in this array.” Most candidates reach for Arrays.sort() and stop. It works. It’s O(n log n). A stronger answer reaches for the heap: sorting processes all n elements in O(n log n) time, while a bounded heap takes O(n log k) and maintains only k candidates — preferable when k is small relative to n, or when the input arrives as a stream. For 1 ≤ k ≤ n, the heap uses O(k) auxiliary space, and the returned result uses O(k) output space. This post builds four common heap patterns that cover a wide range of top-k questions asked in Java interviews, with working code, the complexity math, and the PriorityQueue traps that quietly sink candidates. ...

2026-10-02 · 13 min · Ramesh

Consistent Hashing, Actually Working: From Modulo to a Java Ring with Virtual Nodes

“Design a distributed cache.” You say hash(key) % N. The interviewer nods, then asks: “A node dies at 3 AM. What happens?” If your answer is “we rehash everything,” you’ve just told them your cache has a planned outage every time the cluster changes shape. This post builds the real answer — a working consistent hash ring in Java, with virtual nodes and tests — and the lineage and follow-ups that turn it into a senior-level answer. ...

2026-09-23 · 8 min · Ramesh