Skip to content

Practice Friends Of Appropriate Ages

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#825
LeetCode Problem

Friends Of Appropriate Ages

Problem Statement

For each pair of different people x and y, x sends y a request unless age[y] <= 0.5 * age[x] + 7, age[y] > age[x], or both age[y] > 100 and age[x] < 100. Count all directed requests. Equal ages may belong to different people, no self-request is allowed, and one request does not imply a request in the opposite direction.

Source: Friends Of Appropriate Ages on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
ages = [16,16]
Output
2

# Example 2

Input
ages = [16,17,18]
Output
2

# Example 3

Input
ages = [20,30,100,110,120]
Output
3

Constraints

n == ages.length
1 <= n <= 2 * 10^4
1 <= ages[i] <= 120

Related LeetCode Problems

Practice more problems similar to Friends Of Appropriate Ages.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.