Count Centaur Friend Requests
Problem statement
A group of centaurs sign up for accounts and may send directed friend requests to one another. You are given their integer ages in ages.
A centaur with age x sends a request to a different centaur with age y only when all of these rules hold:
y >= x / 2 + 7, where the division is real-number division.y <= x.- If
x > 100, theny >= 100.
Count the total number of directed friend requests. Centaurs with the same age are still distinct people, and no centaur may send a request to themself.
Function
countCentaurFriendRequests(ages: int[]) → longExamples
Example 1
ages = [120,110]return = 1The 120-year-old centaur sends one request to the 110-year-old centaur. The reverse request is disallowed because the recipient would be older.
Example 2
ages = [120,110,99]return = 1The 99-year-old recipient is disallowed for both senders over 100, so only the request from age 120 to age 110 is sent.
Example 3
ages = [120,45,230,400,88,300,101]return = 4Exactly four ordered sender-recipient pairs satisfy every age rule.
Example 4
ages = [101,120,230,400,88,45,55,300]return = 6Counting valid ordered pairs across all eight distinct centaurs gives six requests.
Example 5
ages = [100,110,120]return = 3The valid requests are from age 110 to 100 and from age 120 to both 100 and 110.
Constraints
1 <= ages.length <= 2 * 10^5.1 <= ages[i] <= 10^9.- Each position in
agesrepresents a distinct centaur.