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.
Hey folks, I can't quite understand why this is a combinatorics problem or why people are having issues with execution times.
My submission just goes over an array and saves how many occurrences of each number exists to a map. Then for each number that occurs more than once, I add n*(n-1) to the result and print it.
Am I doing this inefficient? The time complexity of this is basically just O(N) as I go over the array values once and the map values once and the storage complexity also is O(N) as the map can get at most N elements.
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 →
Hey folks, I can't quite understand why this is a combinatorics problem or why people are having issues with execution times.
My submission just goes over an array and saves how many occurrences of each number exists to a map. Then for each number that occurs more than once, I add
n*(n-1)
to the result and print it.Am I doing this inefficient? The time complexity of this is basically just
O(N)
as I go over the array values once and the map values once and the storage complexity also isO(N)
as the map can get at mostN
elements.