Given an array A of N integers, find the index of values that satisfy P + Q = R + S, where P, Q, R & S are integers values in the array
Expected time complexity O(N2)
NOTE: 1) Return the indicesIf no solution is possible, return an empty list.
A1 B1 C1 D1, so that A[A1] + A[B1] = A[C1] + A[D1] A1 < B1, C1 < D1 A1 < C1, B1 != D1, B1 != C1
2) If there are more than one solutions, then return the tuple of values which are lexicographical smallest.
Assume we have two solutions S1 : A1 B1 C1 D1 ( these are values of indices in the array ) S2 : A2 B2 C2 D2
S1 is lexicographically smaller than S2 if: A1 < A2 OR A1 = A2 AND B1 < B2 OR A1 = A2 AND B1 = B2 AND C1 < C2 OR A1 = A2 AND B1 = B2 AND C1 = C2 AND D1 < D2
1 <= N <= 1000
0 <= A[i] <= 1000
First and only argument is an integer array A of length N.
Return an array of size four which contains indices of values P, Q, R, and S.
A = [3, 4, 7, 1, 2, 9, 8]
A = [2, 5, 1, 6]
[0, 2, 3, 5]
[0, 1, 2, 3]
A + A = A + A Note: indexes returned should be 0-based.
A + A = A + A
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a question? Checkout Sample Codes for more details.