Fractal interview question

Counting duplicates