825. Friends Of Appropriate Ages
825. Friends Of Appropriate Ages
Description
There are n persons on a social media website. You are given an integer array ages where ages[i] is the age of the i^th person.
A Person x will not send a friend request to a person y (x != y) if any of the following conditions is true:
age[y] <= 0.5 * age[x] + 7age[y] > age[x]age[y] > 100 && age[x] < 100
Otherwise, x will send a friend request to y.
Note that if x sends a request to y, y will not necessarily send a request to x. Also, a person will not send a friend request to themself.
Return the total number of friend requests made.
Example 1:
1 | Input: ages = [16,16] |
Example 2:
1 | Input: ages = [16,17,18] |
Example 3:
1 | Input: ages = [20,30,100,110,120] |
Constraints:
n == ages.length1 <= n <= 2 * 10^41 <= ages[i] <= 120
Hints/Notes
- 2025/02/10 Q1
- sliding window
- 0x3Fâs solution
- TODO: use count array to improve the efficiency
Solution
Language: C++
1 | class Solution { |