3 explanation:
inputs are:
platforms). the order is (id, xcoord, ycoord)[
(0, 1, 2)
(1, 2, 3)
(2, 3, 4)
(3, 3, 5)
]bridges). (0,1) means there is an edge between platform 0 and platform 1.[
(0,1)
(1,2)
(2,3)
]02output is:
True/False (depending on getting from start platform to end platform is possible)
for the next question, Take an extra input j that indicates number of jumps that can be made from any platform. This jump can span either x axis or y axis.
E.g.
Platforms [(0, 1, 2), (1, 1, 5), (2, 3, 5)]
Bridges [(1,2)]
start 0
end 2
j 3
Returns True
Because from platform 0, there are no bridges but j is 3, so you can jump to platform 1. From platform 1 to 2, there is a bridge so you can go to platform 2.
My approaches:
My approach was a n^2 time, n^2 space complexity solution. Traverse every point to all points with same x axis, then from the second point, traverse every point to all points with same y axis. Do the same but the axises flipped. Definitely was not the optimal solution.
Did some API designs, system diagrams, but the interviewer did not seem satisfied.
Solved the first part with DFS. Verbally talked about the solution for the follow up question but no time to code it. Definitely was not an optimized solution
Overall I did not expect to get these kind of questions; I thought i was prepared on most algorithms like string, arrays, dp, trees, and graphs, but obviously not enough to comfortably solve these kind of questions.