Back to problems

Get Perfect Pairs Count

Algorithm · Salesforce · Medium

We call an ordered pair of integers (x, y) perfect when it meets both of the following requirements: the smaller of x - y and x + y is at most the smaller of x and y ; the larger of x - y and x + y is at least the larger of x and y . Here, x means the absolute value of x, min(a,b) gives the smaller value among a and b, and max(a,b) gives the larger value. You are given an array arr of length n. Your task is to return the number of index pairs (i, j) such that 0 ≤ i < j < n…

Checking your access…