Tap here to switch tabs
Problem
Submissions

Problem: Friends Of Appropriate Ages

Friends Of Appropriate Ages asks you to count directed friend requests between distinct people where the recipient is older than half the sender's age plus seven, no older than the sender, and not over 100 when the sender is under 100.

Statement

There are n people on a social media platform, with the age of each person given in an integer array ages, where ages[i] represents the age of the ithi^{th} person.

A person x will not send a friend request to a person y if any of the following conditions hold true:

  • ages[y] ≤0.5×\leq 0.5 \times ages[x] +7+ 7

  • ages[y] >> ages[x]

  • ages[y] >100> 100 and ages[x] <100< 100

Otherwise, x will send a friend request to y.

Return the total number of friend requests sent across all people.

Note: If x sends a friend request to y, y does not necessarily send a friend request to x. Additionally, no person can send a friend request to themselves.

Constraints:

  • n ==== ages.length

  • 1≤1 \le n ≤2×104\leq 2 \times 10^4

  • 1≤1 \le ages[i] ≤120\le 120

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Friends Of Appropriate Ages

Friends Of Appropriate Ages asks you to count directed friend requests between distinct people where the recipient is older than half the sender's age plus seven, no older than the sender, and not over 100 when the sender is under 100.

Statement

There are n people on a social media platform, with the age of each person given in an integer array ages, where ages[i] represents the age of the ithi^{th} person.

A person x will not send a friend request to a person y if any of the following conditions hold true:

  • ages[y] ≤0.5×\leq 0.5 \times ages[x] +7+ 7

  • ages[y] >> ages[x]

  • ages[y] >100> 100 and ages[x] <100< 100

Otherwise, x will send a friend request to y.

Return the total number of friend requests sent across all people.

Note: If x sends a friend request to y, y does not necessarily send a friend request to x. Additionally, no person can send a friend request to themselves.

Constraints:

  • n ==== ages.length

  • 1≤1 \le n ≤2×104\leq 2 \times 10^4

  • 1≤1 \le ages[i] ≤120\le 120