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.
I got 100 points using pyhton 3. Some optimizations:
The number of pairs that can be formed using the value 1 in the array is known. We don't have to try to calculate the number of pairs with 1's, there is a simple formula for getting the number of all the pairs that contain 1
I created and kept track of a list of ranges which told how many pairs can be generated with the next value in the array.
The number of ranges for some of the tests were probably going up significantly so I got timeout failures, then I switched to binary search to find the range that the value falls in.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Array Pairs
You are viewing a single comment's thread. Return to all comments →
I got 100 points using pyhton 3. Some optimizations: