cswork / OAOpen practice workspace

SnowflakeOA #17

Perfect Pairs

Estimated MediumStatement and editorial — judging is being prepared

Topics (AI-labelled)Two PointersBinary SearchBits & Math

A pair of integers (x, y) is perfect if both of the following conditions are met: min(|x - y|, |y - x|) ≤ min(|x|, |y|) max(|x - y|, |y - x|) > max(|x|, |y|) Given an array arr of length n, find the number of perfect pairs (arr[i], arr[j]) where 0 ≤ i Function Description Complete the function getPerfectPairsCountin the editor below.getPerfectPairsCount` has the following parameter:

  • int arr[n]: an array of integers Returns int: the number of perfect pairs

Constraints

  • 2 ≤ n ≤ 2*10⁵
  • -10⁹ ≤ arr[i] ≤ 10⁹

Editorial

Loading solution…