Find the Number of Distinct Colors Among the Balls
Track each ball’s color and how many balls show each color in two hash maps, so each repaint updates the distinct count in constant time.
Track each ball’s color and how many balls show each color in two hash maps, so each repaint updates the distinct count in constant time.