← Back to topics
Topic

Not a Triangle

D
Dgleich
Can someone please help me with this task, my idea was to sort the array and then select every 2 combinations and with binary search find the first element that has smaller sum then their and then just return number of them... but for some reason it's failing is there any condition I should check in binary search?
Here is the Submission:http://www.z-trening.com/new/www/html/submit.php?submit=7100050456&subm_stat=1
A
Asmirasmir
Look ,
if everything is sorted then for every j the next solution must be equal or higher from the last one so just remember the position of the last solution and continue from there for the next j.
Also there is no need for binary search.
f
fushar
so what's your solution's time complexity, Asmirasmir?
A
Asmirasmir
its under O(N^2) ( its a nice bit less ), but I'm not in the mood for doing all the maths :D