> For the complete documentation index, see [llms.txt](https://trizen.gitbook.io/sidef-lang/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://trizen.gitbook.io/sidef-lang/programming_tasks/t/two_sum.md).

# Two sum

```ruby
func two_sum(numbers, sum) {
    var (i, j) = (0, numbers.end)
    while (i < j) {
        given (sum <=> numbers[i]+numbers[j]) {
            when (-1) { --j }
            when (+1) { ++i }
            default { return [i, j] }
        }
    }
    return []
}

say two_sum([0, 2, 11, 19, 90], 21)
say two_sum([0, 2, 11, 19, 90], 25)
```

## Output:

```
[1, 3]
[]
```
