Google | Onsite
Difficulty: EASYCategory: InterviewExperienceFrequency: 1Asked On 2024-09-21Added By Anonymous
Source:Β Link
π§ Experience: unknown
β Outcome: unknown
π° Compensation: unknown
π Location: unknown
π’ Company: Google
π Education: unknown
π Benefits: unknown
π Offer Date: unknown
Anyone has the working solution for this with proper graph representation Given an undirected acyclic graph with all of the vertices having at most 3 neighbors. Every vertex is colored either in red or black or white. Please find a root vertex so that: 1. It will form a valid binary tree. 2. Vertices with the same depth are colored with the same color. 3. Color should be changing in R->W->B->R->W->B order as depth increases. Please note that R->B->W->R->B->W is not allowed. (root can be any color, so it can be R->W->B->β¦ or W->B->R->β¦ or B->R->W->β¦ starting from root) Return -1 if we canβt find such a vertex.
β Outcome: unknown
π° Compensation: unknown
π Location: unknown
π’ Company: Google
π Education: unknown
π Benefits: unknown
π Offer Date: unknown
Anyone has the working solution for this with proper graph representation Given an undirected acyclic graph with all of the vertices having at most 3 neighbors. Every vertex is colored either in red or black or white. Please find a root vertex so that: 1. It will form a valid binary tree. 2. Vertices with the same depth are colored with the same color. 3. Color should be changing in R->W->B->R->W->B order as depth increases. Please note that R->B->W->R->B->W is not allowed. (root can be any color, so it can be R->W->B->β¦ or W->B->R->β¦ or B->R->W->β¦ starting from root) Return -1 if we canβt find such a vertex.