Two sum: Difference between revisions

Content added Content deleted
No edit summary
Line 3: Line 3:
;Task
;Task
Given a sorted array of single positive integers, is it possible to find a pair of integers from that array that sum up to a given sum? If so, return indices of the two integers or an empty array if not.
Given a sorted array of single positive integers, is it possible to find a pair of integers from that array that sum up to a given sum? If so, return indices of the two integers or an empty array if not.



;Example
;Example
Line 8: Line 9:
Because numbers[1] + numbers[3] = 2 + 19 = 21,<br/>
Because numbers[1] + numbers[3] = 2 + 19 = 21,<br/>
return [1, 3].
return [1, 3].



;Source
;Source
[http://stackoverflow.com/questions/8334981/find-pair-of-numbers-in-array-that-add-to-given-sum Stack Overflow: Find pair of numbers in array that add to given sum]
[http://stackoverflow.com/questions/8334981/find-pair-of-numbers-in-array-that-add-to-given-sum Stack Overflow: Find pair of numbers in array that add to given sum]

<br/><br/>
<br/><br/>

=={{header|C sharp|C#}}==
=={{header|C sharp|C#}}==
<lang csharp>public static int[] TwoSum(int[] numbers, int sum)
<lang csharp>public static int[] TwoSum(int[] numbers, int sum)