Interview question asked in Paxos and Tiktok interview
Anonymous User
1099

Hello, I was asked this question in Tiktok interview. I was not able to solve it. Just wanted some help with this problem.

It's the year 2200 and Tiktok is deciding to build a new office on Mars.
They're not sure where to build it and they want it to be as close to their other offices as possible. We use a matrix to represent the land.

  • Each 0 is empty land where they can build
  • Each 1 is one of their current offices
  • Each 2 is a blocked off piece of land which cannot be crossed
    Where should the new office be built? (all buildings should be able to reach it)

Input: [[0,0,1,0,0],[0,0,0,0,0],[1,0,2,0,1]]
0 - 0 - 1 - 0 - 0
0 - 0 - 0 - 0 - 0
1 - 0 - 2 - 0 - 1
Output: {1,2}

Input: [[0,0,1,2,0],[0,0,0,0,1]]
0 - 0 - 1 - 2 - 0
0 - 0 - 0 - 0 - 1
Output: {1,2} or {1,3}

Comments (5)