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.
Input the values in an array a[]
Make a temporary array with it temp[] O(n)
Do all the operations in temp[] after which you would know which 2 elements form the sum. O(n*logn)
After that just search for those element's index in the a[] array in O(n) time.
Ice Cream Parlor
You are viewing a single comment's thread. Return to all comments →
Input the values in an array a[] Make a temporary array with it temp[] O(n) Do all the operations in temp[] after which you would know which 2 elements form the sum. O(n*logn) After that just search for those element's index in the a[] array in O(n) time.
Final Complexity= O(n*logn)