Was given a medium level graph question. Title Broadcast and Shutdown
given the name of source and destination router, max rannge of all routers and a map of router name and coordinates, return boolean indicatin wheter a signal sent from source can reach destination.
I confirmed my understanding of the question and asked a clarifying question that do I need to just check x and y or do I calculate euclidean distance for example routers placed at 0,0 and 10,10 with max range should not be able to communicate, he said to ignore this calculating and gave a empty helper method getDistance and asked to use this instead.
I discussed the optimal solution solution to do it in 8-10 minutes and when he accepted the solition I coded it out in next 5-10 minutes making an optimization along the way, I kept explaining the code and adjustments along the way but since he told me after explaining the question "Don't mind me I'm replying to emails" he did not seem to listen to what I was saying. After finishing the code we discussed Time complexity which was O(N2), that because there is a while loop doing the iterations on a queue to do a BFS and for each router I get I find node in it's range so this is also O(N), but I kept a hashset of name of visited router to keep track of where I've been and avoid redundant calculations. He asked me to optimize it and hinted towards the findChildren() method, asked how we represent a graph, that assume the routers are static and won't change , all this is hinting towards an adjacency list , which is not provided and if I have to build this then building the adjacency list itself be an O(N2) and an additional O(N2) space, but finding children along the way helps me keep down the space complexity without increasing time complexity.
This went on for the next 20 minutes, my original solution was done in 25 minutes.
I was not happy with the interview, and received a call from recruitor afrer 2 hours and she told me the feedback was not positive and I need to work on my coding and debugging skills.
I think the interviewer was focused on the O(N2) in traversal and was not able to understand that we can make the traversal O(N) which will force us to build adjacency list which itself will take O(N2) time and O(N2) space.
Cooloff period 12 months!!
Will provide my code in the comment section soon.
Please provide suggesttions if I am wrong so that I don't bomb any other opportunity.