LeetCode 825, Medium. Topics: Array, Two Pointers, Binary Search, Sorting. View on LeetCode.
Generate this problem as a practice environment: tested reference solution, 20 parametrized pytest cases, and a playground notebook:
Problem
<p>There are <code>n</code> persons on a social media website. You are given an integer array <code>ages</code> where <code>ages[i]</code> is the age of the <code>i<sup>th</sup></code> person.</p>
<p>A Person <code>x</code> will not send a friend request to a person <code>y</code> (<code>x != y</code>) if any of the following conditions is true:</p>
<ul>
<li><code>age[y] <= 0.5 * age[x] + 7</code></li>
<li><code>age[y] > age[x]</code></li>
<li><code>age[y] > 100 && age[x] < 100</code></li>
</ul>
<p>Otherwise, <code>x</code> will send a friend request to <code>y</code>.</p>
<p>Note that if <code>x</code> sends a request to <code>y</code>, <code>y</code> will not necessarily send a request to <code>x</code>. Also, a person will not send a friend request to themself.</p>
<p>Return <em>the total number of friend requests made</em>.</p>
<p> </p>
Examples
Constraints
- n == ages.length
- 1 <= n <= 2 * 10^4
- 1 <= ages[i] <= 120
Solution
Reference implementation from solution.py on GitHub, full suite in test_solution.py:
Complexity
Last modified on September 7, 2026