Hacker rank doubt

I’m not getting the approach of the author mainly the last part in which he counts the number of Consecutive Subsequences.

Editorial : Consecutive Subsequences | HackerRank

More specifically explain me this part,

 long long res = 0;
    for(int r = 0; r < k; r ++)
        res += (cnt[r]*(cnt[r]-1)/2);
    cout << res << endl;

it explains that we can choose any two numbers for a pair in nC2 or n*(n-1)/2 ways.

Reference arrays - Number of subarrays divisible by k - Stack Overflow

1 Like