#825

Friends Of Appropriate Ages

specialist · 940 · lc medium +32 · verified · 49.9% accepted · 880 likes · top 37%

Description

There are n users on a social platform. You are given an integer array ages where ages[i] is the age of user i.

User x will NOT send a friend request to user y (x != y) if any of the following conditions holds:

- age[y] <= 0.5 * age[x] + 7

- age[y] > age[x]

- age[y] > 100 && age[x] < 100

Otherwise, x does send a request to y. Requests are not necessarily reciprocal; no user sends a request to themselves.

Return the total number of friend requests sent.

Example 1:

Input: ages = [16,16]
Output: 2
Explanation: 2 people friend request each other.

Example 2:

Input: ages = [16,17,18]
Output: 2
Explanation: Friend requests are made 17 -> 16, 18 -> 17.

Example 3:

Input: ages = [20,30,100,110,120]
Output: 3
Explanation: Friend requests are made 110 -> 100, 120 -> 110, 120 -> 100.

Code

1
2
3