Problem 3160 · Medium

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.

Open the interactive visualisation