Description
Solutions
Submission
Cleaning Robot

There is a cleaning robot which is cleaning a rectangular grid of size N x M, represented by array R consisting of N strings. Rows are numbered from 0 to N-1 (from top to bottom) and columns are numbered from 0 to M-1 (from left to right).

The robot starts cleaning in the top-left corner, facing rightwards. It moves in a straight line for as long as it can, in other words, while there is an unoccupied grid square ahead of it. When it cannot move forward, it rotates 90 degrees clockwise and tries to move forward again until it encounters another obstacle, and so on. Dots in the array (".") represent empty squares and "X"s represent occupied squares (ones the robot cannot move through). Each square that the robot occupied at least once is considered clean. The robot moves indefinitely.

Function Description

Write a function:

public int cleaningBot (String[] R)

that, given an array R consisting of N strings, each of length M. representing the grid, returns the number of clean squares.

Example 1:

Input:  R = ["...X..", "....XX", "..X..."]
Output: 6
Explanation:
Constraints:
    Unknown for now 🥹
Thumbnail 0
Thumbnail 1
Testcase

Result
Case 1

input:

output: