Search topics...
All Problems

Friends Of Appropriate Ages

Solution Approach
Was this helpful?
MediumarrayExpected: O(1) time, Unknown space
sorting

Problem

Given an array of ages, determine the total number of friend requests made based on age conditions.

Example 1:

Input: ages = [16, 16]
Output: 2
Explanation: Both people send requests to each other.

Example 2:

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

Example 3:

Input: ages = [20, 30, 100, 110, 120]
Output: 3
Reference solution unlocks after your first submission
Loading...