Amazon | Phone | Mario and Princess
Anonymous User
2603

I was asked the following question recently in my first phone screen

Given N platforms and M ladders find if Mario can reach princess.
Platform is repsented by (X,Y) corodinate pair
Ladder is represented by (p1,p2) which means you need a ladder to go from p1->p2
There are 2 ways to reach from p1-p2

  1. if distance between them is less than given distance 'D'
  2. if there is ladder between 2 platforms

Mario is one platform and Princess is on another platform, so find if there is way for Mario to reach princess

I proposed a solution with BFS as follows

  1. construct a graph with ladders
  2. add mario's platform to queue
  3. pop from queue and check if there is direct way(without ladder) from this plattform and add all those to queue (check if popped platform coordinates are same as given 'princess' coordinates means we could reach the end so return True)
  4. then add all platform that can be reached using ladders

I felt this is a general BFS problem, interviewer said yes it can be solved using BFS he asked some
questions on optmizing i said we need not find all platforms for each node everytime but can precompute it but i didnt have much time to discuss about optmizations

Not sure what is wrong i got a reject. I am trying hard to understand how these FAANG companies evaluate candidates.I agree there might be some optmization possible here but this is my first phone screen so i thought i would be called for a next phone screen if not onsite directly but i got a straight reject. Is something wrong in this approach? And companies does not provide feedback at all so dont understand where did i go wrong. I am getting little frustrated with the rejects

Comments (5)