algorithm - Given 3 sorted arrays A, B, C and number S, find i, j, k such that A[i] + B[j] + C[k] = S -
I just learned how to solve it in O (n ^ 2 log n) For each A [i]: For every B [J]: If A [I] + B [J] + C Birrinary Search (The time taken to handle every AR is the same):
S - A [A] - B [J]] == S: Returns (I, J, K) To fix this, O (n ^ 2) to improve the time or the above algorithm?
if arrays are non-negative, * you * all 3 arrays are s => [N] & gt; S [Aidx] + B [BIDX]> S
Comments
Post a Comment