Back to Question

Battleships in a Board

Question Explain

Given an $m \times n$ board where 'X's represent battleships and '.'s represent water, count the number of battleships. Battleships are placed horizontally or vertically, and are separated by water. Solve in $O(n)$ without modifying the board.

Start Trying This Question Simulation

Click "Start Speaking" and answer the question naturally.