Practice problem · Medium

Battleship

Battleship: ships occupy multiple cells on a grid. 3 stages in Python with an AI assistant. Stage 1 free.

Stage 1 of 3: Fix bugs

Background. Battleship: ships occupy multiple cells on a grid. You fire shots at coordinates; each shot is a HIT, a MISS, or a DESTROYED (the shot that sinks the ship). The goal is to sink every ship — ideally in as few shots as possible.

grid.py defines Grid, the ocean that holds ships and resolves shots.

The starter has bugs. Two tests in test_grid.py fail.

Find them and fix them. Don't change the public interface.

Done when Submit goes green.

Constraints

  • Python 3.12+ standard library only
  • Time limit: 15 seconds per test
  • Editable: grid.py (Stage 1) and hunter.py (Stages 2, 3)
  • Read-only: ship.py, play.py, all test_*.py files

What comes after stage 1

The next stages open once the tests for the one before them pass. Each raises the bar, the way an interviewer does in the room.

  1. Stage 2: Implement hunter. Write a hunter that sweeps the grid until every ship is sunk; any working approach passes.
  2. Stage 3: Optimize. Sink the fleet in far fewer shots than a sweep: a real search strategy against a measured bar.

The files you get

  • Yours to edit: grid.py, hunter.py.
  • Read-only: ship.py, play.py.
  • Tests you can read and run: test_grid.py. Hidden tests run on Submit.

The round: an agent in the editor

The assistant here works like the one in the interview IDE. It reads your files, runs code and proposes changes, and you accept or reject each one. It doesn't volunteer ideas, so what gets built is what you asked for. Along the way the interviewer asks about your decisions, and at the end the report says what you checked and what you accepted unread.

Frequently asked, briefly answered

Is Battleship free?

Stage 1 is free with an account. The other 2 stages need Nyrion Pro.

Which company asks something like this?

No single company. It is practice for the format itself: an existing codebase, an assistant in the editor and a bar that rises stage by stage.

Do I bring my own AI tool?

No. The assistant is in the editor, same as in the interview IDEs at Meta, Stripe and Amazon. What you choose at Begin is the format: an agent that proposes changes you accept or reject, an answer-only assistant that can't write code, or no assistant at all.

What does the interviewer ask?

4 questions along the way about your own code, and one at the end about the whole session. A weak answer gets one follow up. The answers go into the report, which ends with a hire or no hire verdict.

Start the problem

Sign in and the problem opens where you left it. New here? An account takes a minute to create, and the first stage of this problem is free.

Start this problem → Sign in

More like it: every practice problem, the AI coding interview guide.