825. Friends Of Appropriate Ages Medium
1/**
2 * [825] Friends Of Appropriate Ages
3 *
4 * 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.
5 * A Person x will not send a friend request to a person y (x != y) if any of the following conditions is true:
6 *
7 * age[y] <= 0.5 * age[x] + 7
8 * age[y] > age[x]
9 * age[y] > 100 && age[x] < 100
10 *
11 * Otherwise, x will send a friend request to y.
12 * 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.
13 * Return the total number of friend requests made.
14 *
15 * Example 1:
16 *
17 * Input: ages = [16,16]
18 * Output: 2
19 * Explanation: 2 people friend request each other.
20 *
21 * Example 2:
22 *
23 * Input: ages = [16,17,18]
24 * Output: 2
25 * Explanation: Friend requests are made 17 -> 16, 18 -> 17.
26 *
27 * Example 3:
28 *
29 * Input: ages = [20,30,100,110,120]
30 * Output: 3
31 * Explanation: Friend requests are made 110 -> 100, 120 -> 110, 120 -> 100.
32 *
33 *
34 * Constraints:
35 *
36 * n == ages.length
37 * 1 <= n <= 2 * 10^4
38 * 1 <= ages[i] <= 120
39 *
40 */
41pub struct Solution {}
42
43// problem: https://leetcode.com/problems/friends-of-appropriate-ages/
44// discuss: https://leetcode.com/problems/friends-of-appropriate-ages/discuss/?currentPage=1&orderBy=most_votes&query=
45
46// submission codes start here
47
48impl Solution {
49 pub fn num_friend_requests(ages: Vec<i32>) -> i32 {
50 0
51 }
52}
53
54// submission codes end
55
56#[cfg(test)]
57mod tests {
58 use super::*;
59
60 #[test]
61 fn test_825() {
62 }
63}
64
Back
© 2025 bowen.ge All Rights Reserved.