AiLearn AI Coding
easyStructured · sandbox45 min Premium

Battleship

Track ship placement and attack resolution on a board, data structure design with a bug → feature → scale arc.

Data Structures

Problem

Your starter code has a Board class that places ships and tracks attacks. It mostly works — but placement validation is buggy.

Phase 1 — Fix the bug

place(ship) currently accepts ships that overlap an existing ship or extend past the board edge. Both cases should throw a PlacementError.

Phase 2 — Feature

Add fire(target: Cell): HitResult that records a hit or miss, and reports { shipId, sunk } the moment every cell of a ship has been hit. A ship is sunk only when all of its cells are hit.

Phase 3 — Scale

The board grows from 10×10 to 1000×1000, and attacks arrive in batches of thousands. Your board representation and hit-tracking must stay fast.

What interviewers watch

A fast board representation (map vs. grid), clean "all ships sunk" logic, and careful review of AI-generated placement code — overlaps and bounds are classic AI slips.