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.
Collect sorted occurrences of a and b, then sweep both lists with one moving pointer to find a nearby b for each a.