Google L4 Interview Experience
Company: Google
Role: L4
Interview Stage: Phone Screen
Location: unknown
Year: unknown
Original Post Content:
Round 1:
Question: Given some neighborhoods (say 3) each having some houses (say 3) and each house represented by a number. Find a way to rearrange houses such that:
1. No two houses in the same neighborhood have the same number
2. Each neighborhood has the house numbers in ascending order
There will always be at least one solution. If there are multiple solutions return anyone of them.
Example: ((7,8,9), (4,6,4), (4,2,6))
Output: ((4,6,8), (2,4,9), (4,6,7))
I messed up in the interview and started coding without a clear idea first. Then I changed multiple approaches midway and wasted a lot of time. But the best I could do was to find the frequency map of the numbers then arranged it in the order of frequency like this:
[
[7,8,9,2], # numbers having frequency 1
[6], # numbers having frequency 2
[4] # numbers having frequency 3
]
Then I wanted to go in reverse order and assign the highest frequency elements to empty buckets, but I messed up in the assignment part. Would be grateful if someone could help with the correct approach for this.