• + 1 comment

    How is this challenge related to sorting?

    I solved it by counting the number (N) of times an integer occurs in the array (one traversal, no need for sorting), then summing 2*nCr(N, 2) for N >= 2.

    Can sorting improve the algorithm?