My first instinct was to just scan every cell row by row which is O(N^2) calls and technically correct but they pushed back immediately asking if I could do better.
Use a parity-based search to reduce the number of API calls: bomb every other cell to find a hit, then determine the ship's orientation and exact position with a few additional calls. Discuss the worst-case complexity, which is O(N^2) but with a constant factor of about 1/2, and mention that it's optimal in the worst case.
Pro tip: Mention that the parity strategy is optimal in the worst case because an adversary can place the ship to avoid all parity cells, but you can still guarantee finding it with at most ceil(N^2/2) + O(1) calls. Also, clarify that the API call complexity is measured in terms of the number of bomb_location calls.
Confirm that the ship is exactly length 3, placed horizontally or vertically, and that the grid is N×N. Ask if the ship can be at the edges and if the API returns true only for occupied cells.
Bomb all cells with (x+y) even (or odd) to find at least one hit. Since the ship occupies 3 consecutive cells, it must contain at least one cell of each parity, so this guarantees a hit.
Once a hit is found, check adjacent cells to determine if the ship is horizontal or vertical, then bomb the remaining cells along that line to identify all three occupied cells.
Count the maximum number of bomb_location calls: about N^2/2 for the parity search plus at most 4 additional calls to confirm orientation and position. Conclude that the worst-case complexity is O(N^2) with a constant factor of 1/2.
Explain that any algorithm must make at least ceil(N^2/2) calls in the worst case because the adversary can place the ship to avoid all cells of one parity, so the parity strategy is asymptotically optimal.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.