Find Number of Perfect Pairs
Updated
Problem statement
Given an array, find the number of perfec pairs.
(x, y) is a perfect pair if satisfies:
- min(|x-y|, |x+y|) <= min (|x|, |y|) and max(|x-y|, |x+y|) > max(|x|, |y|)
Function
findNumberOfPerfectPairs(arr: int[]) → intExamples
Example 1
arr = [2, 5, -3]return = 2out of (2, 5) , (5, -3) and (2, -3), (2, -3) and (5, -3) satisfy both the conditions. Therefore, the output is 2.
More Salesforce interview questions
- Count Increasing TripletsONSITE INTERVIEW · Seen Nov 2026
- Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
- Reverse a Sublist of a Linked ListONSITE INTERVIEW · Seen Nov 2026
- Rotting OrangesONSITE INTERVIEW · Seen Nov 2026
- 3Sum SmallerONSITE INTERVIEW · Seen Nov 2026
- Count Zero Request ServersONSITE INTERVIEW · Seen Nov 2026
- Count Subarrays With Product Equal to KOA · Seen Nov 2026
- Minimum No-Repeat Segments After One Character RemovalOA · Seen Nov 2026
- Get Message StatusOA · Seen Nov 2026
- Group Identical Tree LevelsONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Minimum Rounds to Complete All TasksInfosys · OAInfosys interview questions
- Capping Portfolio WeightsCapstone Investment Advisors · OA
- Count Subarrays with a Perfect-Square ProductMicrosoft · OAMicrosoft interview questions
- Repeated Mirror XORMathWorks · OAMathWorks interview questions
- Stacked Item and Category DiscountsPalantir · OAPalantir interview questions
- Minimize Adjacent Squared-Difference Cost with One InsertionMcKinsey & Company · OAMcKinsey & Company interview questions
- Maximize Revenue from Decreasing InventoryChubb · OAChubb interview questions
- Minimum Power-of-Two Removal OperationsIBM · OAIBM interview questions
- Macaron Order PriceOpenAI · OAOpenAI interview questions
- Daily Settlement for Long and Short PositionsBelvedere Trading · OA