825-Friends-Of-Appropriate-Ages
Sat 17 May 2025
https://leetcode.com/problems/friends-of-appropriate-ages
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
def numFriendRequests(self, ages: List[int]) -> int:
ans = 0
count = [0] * 121
for age in ages:
count[age] += 1
for i in range(15, 121):
ans += count[i] * (count[i] - 1)
for i in range(15, 121):
for j in range(i // 2 + 8, i):
ans += count[i] * count[j]
return ans
new Solution().numFriendRequests()
Score: 5
Category: leetcode