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 wrote and asks you to explain it.
Sessions need a wider screen.
A session is a code editor, the tutor and a test runner, side by side. Together they need about a laptop’s width.
Sign up now and your free problem will be waiting.
A session, with the problem solved
Approach, complexity, then code. The tutor asks for the plan before the syntax and keeps asking after the tests pass.
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 bestWidest Water Between Posts
An array heights gives the height of a vertical post at each index. Choosing two posts i < j, the water they hold is (j - i) * min(heights[i], heights[j]).
Return the maximum water any pair of posts can hold. If fewer than two posts exist, return 0.
Example
heights = [1, 8, 6, 2, 5, 4, 8, 3, 7]
# -> 49 (posts 1 and 8: (8 - 1) * min(8, 7))Constraints
0 <= len(heights) <= 10^50 <= heights[k]values fit in 64-bit ints
# Tests for "Widest Water Between Posts" — read-only. The harness owns this file.
# Hidden tests run too. Their inputs and expected outputs are not shown here,
# so passing everything below is not yet proof the solution is right.
from solution import solve
def test_sample_1():
assert solve([1, 2, 1]) == 2
def test_sample_2():
assert solve([4, 3]) == 3Sweet. Looks like you've solved the exercise!
Good job! You can continue to improve your code or, if you're done, submit it to your tutor for a final review.
- PassedTest 1Sample 1
- PassedTest 2Sample 2
- PassedTest 3Hidden 1 — classic wide container; moving the taller wall misses it
- PassedTest 4Hidden 2 — tall pair far apart
- PassedTest 5Hidden 3 — large interior pair
- PassedTest 6Hidden 4 — all zero → area 0
- PassedTest 7Hidden 5 — monotonic decreasing
- PassedTest 8Hidden 6 — single post → 0
- PassedTest 9Hidden 7 — no posts → 0
- Hidden tests run server-side
- Difficulty-weighted score
- Your code carried through the session
- How it works
Not another problem grinder
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.
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 don’t have to be a coder yet
Ask what a line does and it will walk you through it. Learn how working code works, and why, before you can write it.
while left < right:That question up there is yours to answer. The next question is yours to answer.
One problem, free, no card. Talk through it and find out what you sound like before someone else is listening.