Skip to main contentCode.Socratic
Sign inStart free

Socratic interview practice

You may know coding, but can you talk about it?

Interviews are a conversation, not a submit button. Code.Socratic reads the code you actually wrote and asks you to explain it out loud.

A session, with the problem solved

Python

Widest Water Between Posts

Medium
credits 46
solution.py
def solve(heights):
    left, right = 0, len(heights) - 1
    best = 0

    while left < right:
        width = right - left
        best = max(best, width * min(heights[left], heights[right]))

        # The shorter post caps this pair, and every pair still to come
        # behind it is narrower — so it can never beat what we have.
        if heights[left] <= heights[right]:
            left += 1
        else:
            right -= 1

    return best
hints 011:38
You
Two pointers, one at each end. Each step I move the shorter post inward.
Tutor
Why the shorter one? Say what you throw away when you move it.
You
Every pair that used that post. The width only shrinks from here, and that post already caps the height.
Tutor
Good. So the loop is O(n), one pass, no extra space — agreed. Write it.
You
Done. Both samples and all seven hidden tests pass.
Tutor
They do. Harder question, and it is the one an interviewer asks next: what happens on the step where the two posts are exactly equal, and why is it safe to move either?
  • Hidden tests run server-side
  • Difficulty-weighted score
  • Your code carried through the session

Not another problem grinder

Two-player

Coding was never single-player

Every turn goes both ways: you explain, it pushes back, you answer. Nothing here is graded by a submit button.

Memory

It remembers your code, then asks why

The tutor carries your actual solution through the session, so the question is never generic. It asks about the line you wrote, and why you chose it.

Any level

You don’t have to be a coder yet

Ask what a line does and it will walk you through it. You can learn how working code works, and why it was written that way, before you can write it.

Your turn

That question up there is yours to answer.

One problem, free, no card. Talk through it and find out what you sound like before someone else is listening.