FastPrepCount Perfect Pairs
Problems/Count Perfect Pairs

Count Perfect Pairs

Adyen logoAdyen● MediumFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report gives both perfect-pair inequalities. It comes from an Adyen one-hour HackerRank assessment.

We chose how to count index pairs, the number limits and the function signature.

Our version is about 97% the same as the reported question.

You are given an integer array nums. Look at every index pair (i, j) with i < j. Let x = nums[i] and y = nums[j]. The pair is a perfect pair when both of these conditions hold:

  • min(|x - y|, |x + y|) <= min(|x|, |y|).
  • max(|x - y|, |x + y|) >= max(|x|, |y|).

Return the number of perfect pairs.

Function

countPerfectPairs(nums: int[]) → long

Examples

Example 1

nums = [1,2,3]return = 2

The pair made of the first and last values fails the first condition. The pairs with values (1, 2) and (2, 3) meet both conditions, so they are the only perfect pairs.

Example 2

nums = [0,0,0]return = 3

All values are zero, so for every pair each side of both conditions is zero. Zero is at most zero and at least zero, so every pair is a perfect pair.

Constraints

  • 1 <= nums.length <= 8,000.
  • -10^9 <= nums[i] <= 10^9.

More Adyen interview questions

  • Maximize Strength with Disjoint Adjacent SwapsOA · Seen Aug 2026
  • Best TV Show in a GenreOA · Seen May 2026
  • Search and Format ContactsPHONE SCREEN · Seen Nov 2026
  • Find the Tree DiameterONSITE INTERVIEW · Seen Aug 2026
  • Planets Queries from Planet OnePHONE SCREEN · Seen May 2026

Similar questions at other companies

  • Maximum Easy Tasks After RearrangingIBM · OA
  • Latest Arrival to Catch a BusAutodesk · OA
  • Minimum Removals to Balance ArraySalesforce · OA
  • Profitable Project PairsAkuna Capital · OA
  • Most Employees Working at OnceCitadel · OA
  • 3SumAT&T · OA
  • Minimum Height Difference Between Distant PeaksRoblox · OA
  • Minimum Machines for TasksExpedia · OA
  • Find Minimum Possible SizeMathWorks · OA
  • Count Pair Sums in a RangeAdobe · OA

Adyen interview experiences

  • Adyen Kotlin Backend Engineer Live Coding: 1 Experience
See Adyen hiring insights
Saved
class Solution {
    public long countPerfectPairs(int[] nums) {
        // Count qualifying index pairs.
    }
}
Checking account…