Count Perfect Pairs
Updated
Problem statement
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[]) → longExamples
Example 1
nums = [1,2,3]return = 2The 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 = 3All 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
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