Friend Requests by Age
Problem statement
Each value in ages is one person's age. A person of age A sends a directed friend request to a different person of age B exactly when both conditions hold:
B > 0.5 * A + 7.B <= A.
Return the total number of directed friend requests. People of the same age may request each other, but nobody may request themself.
Function
numFriendRequests(ages: int[]) → intExamples
Example 1
ages = [16,16]return = 2Each sixteen-year-old sends one request to the other.
Example 2
ages = [16,17,18]return = 2The seventeen-year-old may request the sixteen-year-old, and the eighteen-year-old may request the seventeen-year-old.
Example 3
ages = [20,30,100,110,120]return = 3The valid directed requests are 110 -> 100, 120 -> 110, and 120 -> 100.
Constraints
1 <= ages.length <= 20000.1 <= ages[i] <= 120.