3SUM solved by 828

Feb. 21, 2014, 4:24 p.m. by Rosalind Team

Topics: Sorting

Problem

Given: A positive integer $k \le 20$, a postive integer $n \le 10^4$, and $k$ arrays of size $n$ containing integers from $-10^5$ to $10^5$.

Return: For each array $A[1..n]$, output three different indices $1 \le p < q < r \le n$ such that $A[p]+A[q]+A[r]=0$ if exist, and "-1" otherwise.

Sample Dataset

4 5
2 -3 4 10 5
8 -6 4 -2 -8
-5 2 3 2 -4
2 4 -5 6 8

Sample Output

-1
1 2 4
1 2 3
-1

Please login to solve this problem.