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.
My algorithm is the same as yours. Did it in C++ though. I was failing the exact same testcases with Wrong Answer. Turns out it was due to integer overflow. My advice: don't use a plain int for count. Use long long or unsigned long long. Think about the extreme case where N is 10^5 and every A[i] holds the same number. count will overflow.
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 →
My algorithm is the same as yours. Did it in C++ though. I was failing the exact same testcases with Wrong Answer. Turns out it was due to integer overflow. My advice: don't use a plain int for
count
. Uselong long
orunsigned long long
. Think about the extreme case whereN
is 10^5 and everyA[i]
holds the same number.count
will overflow.