Skip to main content

Cisco

Cisco OA-10 2023

Problem Description

The blueprint of a room is represented by a 2D array of 1's and 0's, where:

  • 1 represents walls.
  • 0 represents empty spaces.

Task: Group the empty spaces into rooms with labels matching their size. For example, if a bounded space is 3 units in size, replace the 0's in that space with 3. If the room is only 1 space, leave it as 0.

Input Format:

  • The first line contains the number of rows r.
  • The second line contains the number of columns c.
  • Each of the next r lines contains a row of 0's and 1's of length c.

Output Format:

  • The output contains r lines, each with c values representing 1, 0, or the room size.

Assumptions:

  • The outer boundary of the 2D array is always 1 (walls).
  • Rooms are fully enclosed by walls.
  • Diagonal movement is not allowed.
  • Each position in the 2D array counts as 1 unit of space.

Constraints:

  • 3 ≤ r, c ≤ 100.