Basics/TeamNote/twoPointer.js
// Searching pairs in a sorted array
Searching pairs in a sorted array
Searching pairs in a sorted array
function twoPointer(A, X) {
  const N = A.length;
  for(let i = 0; i < N-1; i++) {
    for(let j = i+1; j < N; j++) {
      if(i === j) continue;
      if(A[i] + A[j] === X) return 1;
      if(A[i] + A[j] > X) break;
    }
  }
  return 0;
}
function twoPointer ( A , X ) { const N = A . length ; for ( let i = 0 ; i < N - 1 ; i ++ ) { for ( let j = i + 1 ; j < N ; j ++ ) { if ( i === j ) continue ; if ( A [ i ] + A [ j ] === X ) return 1 ; if ( A [ i ] + A [ j ] > X ) break ; } } return 0 ; }
Searching pairs in a sorted array
Searching pairs in a sorted array