FLIPKART Coding Question – Solved

8 Live
You are given a board of size M × N where each cell can be either empty ('O') or a wall ('X'). A robot is initially placed at the top-left cell (0,0) and can move in four directions: up, down, left, and right — but not diagonally. The robot can only move through empty cells and cannot pass through or land on walls. Your task is to print the maximum number of empty cells the robot can visit starting from the top-left cell, including the starting cell. Input Format: - First line: Two integers M and N — the number of rows and columns of the board. - Next M lines: Each contains a string of length N, consisting of characters 'O' and 'X'. Output Format: - A single integer — the number of empty cells the robot can visit. Constraints: - 1 ≤ M, N ≤ 100 Sample Input 1: 4 3 OXO OOX XOO OOO Sample Output 1: 8 Explanation: Starting at (0,0), the robot can move through a connected component of 8 'O' cells. One cell ('O' at (0,2)) is isolated and cannot be reached. Sample Input 2: 4 3 000 00X OXO X00 Sample Output 2: 6 Explanation: Starting at (0,0), the robot can visit 6 cells before being blocked by walls.

Asked in: FLIPKART

Image of the Question

Question Image Question Image Question Image

All Testcases Passed ✔



Passcode Image

Solution


Please login to view the solution


Related Questions

| Undirected Coloured Graph Shortest Path You are given an undirected weight… |
| Village Voyage A computer game "Village Voyage" has N villages (labeled 1 to… |
| Academic Decathlon Students are being selected for an academic decathlon tea… |
| Sum of Arrays Given two arrays each of length n, arr1 and arr2, in one opera… |
| Count Swaps During Custom Sorting Analyze the efficiency of the following so… |
| Stacey is coordinating a beach clean-up event with her university's Women in ST… |