Problem 3008 · Hard

Find Beautiful Indices in the Given Array II

Collect sorted occurrences of a and b, then sweep both lists with one moving pointer to find a nearby b for each a.

Open the interactive visualisation