We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
It is a combinatorics problem because we choose 2 from every repeating number group count and here also order is taken into consideration so it is P(k, 2) which is equal to k*(k-1) when simplified (k:repeating number group count).
I did the same thing and I think it is efficient. We cannot decrease it under O(n) because we have to read the array at least..
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Sherlock and Pairs
You are viewing a single comment's thread. Return to all comments →
It is a combinatorics problem because we choose 2 from every repeating number group count and here also order is taken into consideration so it is P(k, 2) which is equal to k*(k-1) when simplified (k:repeating number group count).
I did the same thing and I think it is efficient. We cannot decrease it under O(n) because we have to read the array at least..