Amazon interview question

Battleships on the board - Leetcode