Problem 2615 · Medium

Sum of Distances

Group equal values, then use running sums of their positions to get each index’s total distance to the others in one pass per group.

Open the interactive visualisation