Level: Senior-Level
Round: Phone Screen · Type: Coding · Difficulty: 6/10 · Duration: 60 min · Interviewer: Neutral
Topics: Algorithms
Location: San Francisco Bay Area
Interview date: 2026-01-24
Got offer: False
I had a phone screen for a PE role at Meta. I was asked one coding question related to the Battleship game.
I was asked a coding question about the Battleship game. I hadn't seen this problem before. I initially suggested a brute force approach, then considered 4 directions, and then 2 directions. After the interviewer said my code was correct, they kept focusing on minor optimizations, such as whether calculating 'm-1' would take up too much time or whether adding an 'if' statement would be too costly. I was not given a second question.
The problem was:
You are given a square grid of size N, where N>=3. I have placed a battleship of size 3 somewhere in the grid, and you want to sink my battleship by ordering the bombing of specified coordinates. The battleship can only be placed vertically or horizontally, not diagonally. Every coordinate which does not contain the battleship is empty.
Your task is to write the find_battleship function which takes N as input, and returns the 3 coordinates of the battleship. Assume you have a function, boolean bomb_location(x, y), which will return True if (x, y) "hits" the battleship and False if (x, y) misses the battleship.
For example, in the following grid your function find_battleship(N),
given N of 8, would return ((1,2), (2,2), (3,2)):
. . . . . . . . . . X . . . . . . . X . . . . . . . X . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .