# Leetcode 825 - Friends Of Appropriate Ages

Note:

• Double pointer: Based on 0.5x + 7 < y <= x, use two pointers to find the interval.
• Note that from x > 0.5x + 7 we get x > 14.
• Don’t reset left and right inside loop. Because we can restart from last positions.
• Brute force: Put every age into a map.
• From j = 0.5x + 8 to x, if map.has(j), requests we can make is len - 1 (exclude itself).

Question:

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] + 7
• age[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:

Code:

Double Pointer O(nlogn)

Hash Table Brute Force