Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • 4
    Also, after sorting, discard all the numbers which are bigger than sum. I assume that you have all positive integers. Commented Apr 19, 2010 at 11:03
  • yeah that's what i though and then i got all busy trying to compute the complexity it never occured to me that both the operations are o(nlogn) Commented Apr 19, 2010 at 11:34
  • 1
    You don't have to search for every elements actually. Since you've sorted the array, stop searching at sum/2 (doesn't impact the big O, but still :p) Commented Apr 19, 2010 at 13:27
  • Discarding those bigger numbers wouldn't that break the algorithm if there's negative numbers?. Commented Sep 15, 2024 at 11:18