Popular Posts

Tuesday, August 30, 2011

Problem:
Given an array of integers. How do we pick two numbers such that their sum is closest to zero.
Solution: 

  • Sort the array by comparing absolute value.
  • traverse the array once to find the two consecutive numbers with minimum sum.

Complexity: O(n log n)
Code:



No comments:

Post a Comment