Free written solutionRabbits in Forest (LeetCode 781): Solution and Explanation
Each rabbit you asked tells you how many other rabbits share its colour. Find the smallest forest consistent with all the answers. Group rabbits by their answer and pack each group into as few colours as possible.
Read the intuition, approach, code and complexity →