Amazon Interview Question
InternsCountry: India
Interview Type: Phone Interview
this is typical two colors problem. You can start at any office with for example tester in it, then check all directly connect offices, if there is one that has tester, then report no. Otherwise, assign all the neighbor offices with mark developer, so on and forth. Time complexity is O(E), space complexity is O(V).
This is can be done in two ways:
1. Check if there is odd number of cycle. If it is then it is NO
2. If it is even number of cycle the print yes
3.If it doesn't contain cycle print yes.
-This is a bi-partite graph.
Second method:
DFS
Check if there is an edge from child to parent. If it is then check whether the parent is "Tester or Developer". If it is same as child then Print NO. Otherwise "Yes".
Construct a graph and see whether it is bipartite or not.
- Pras January 25, 2014Let us say u represent a developer node by red color and tester by green color, walls as edges . If no two adjacent nodes have same color then Answer to the manager question is YES or else it is a NO