Amazon ng sde vo coding experience
The interviewer was an old Indian, and he didn't provide the problems; everything was explained verbally. When encountering such an interviewer, it's essential to clarify what the problem is about. If you blindly start writing, you may end up answering the wrong question.
One whiteboard question, similar to the problem from this website:
One interviewer’s verbal problem:
Amazon has many services, and each service has dependencies on others. After we shut down some of these services, find out which services will be affected.
Clarify question:
It’s very important to first clarify the conditions of the problem. Ask the interviewer for an example. The interviewer wasn’t prepared and drew a diagram on the spot. After asking this question, it was confirmed that this was a topology sorting problem.
Is it possible for the problem to be invalid?
For example, is there a possibility of a cycle?
-> The input will always be valid.
Can the input format be customized?
-> Yes, we define the input as a hashmap where the key is the service name and the value is a list of services it depends on.
Ideas:
Before writing the code, make sure to explain your thought process clearly because Amazon’s code can’t be run directly. If you just start writing code and the interviewer doesn’t approve, you might fail. So, explain your approach before writing the code.
Count the in-degree of each service.
Add services with an in-degree of 0 to the queue.
Initialize an affected services set. Initially, the services that are shut down will be added to this set.
Process the queue, popping from the front each time.
Check the list of dependent services. If the current service is in the affected services set, add the dependent services to the set as well. Also, update the in-degree of the dependent services. If the in-degree becomes 0, add them to the queue.
When the queue is empty, return the affected services set.
Time/Space Complexity Analysis:
Dry Run:
Since the code can’t be executed, you need to manually run examples. This step requires a lot of practice.


