[InterviewBit] Array 3 Pointers

Array 3 Pointers

  • Time :
  • Space :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
int Solution::minimize(const vector<int> &A, const vector<int> &B, const vector<int> &C) {
int i = 0, j = 0, k = 0;
int n = A.size(), m = B.size(), l = C.size();
int res =INT_MAX;
while(i < n and j < m and k < l) {
res = min(res, max({abs(A[i]-B[j]), abs(B[j]-C[k]), abs(C[k]-A[i])}));
if(A[i] <= B[j] and A[i] <= C[k] and i + 1 < n) i++;
else if(B[j] <= A[i] and B[j] <= C[k] and j + 1 < m) j++;
else if(C[k] <= A[i] and C[k] <= B[j] and k + 1 < l) k++;
else break;
}
return res;
}

Author: Song Hayoung
Link: https://songhayoung.github.io/2022/09/27/PS/interviewbit/array-3-pointers/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.