Google | Phone | War House
Anonymous User
1558

You are installing bomb to a war house with multiple rooms. The war house is designed such that between any two rooms, there is always a unique path. Each bomb can destory a room, and all rooms adjacent to it. Return the minimum number of bombs needed to cover the war house.

class Room {
  int number; // [0, N)
  List<Integer> adjacent;
}

int solve(List<Room> rooms) {
  // your solution here
}

Example:

0 - 1 - 2 - 3
    |   |
    4   5

Input:
[
  {0, [1]},
  {1, [0, 2, 4]},
  {2, [1, 3, 5]},
  {3, [2]},
  {4, [1]},
  {5, [2]}
]

Output:
2
Comments (5)