Trains the technique from
LeetCode 825Friends Of Appropriate AgesThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A club's members have the ages ages. A member x sends an invitation to a different member y exactly when both of these hold:
y is no older than x;y's age is more than half of x's age plus seven.Invitations go one way only, so x inviting y and y inviting x are counted separately, and nobody invites themselves.
Return how many invitations go out altogether.
Example 1
Neither member is older than the other, and fifteen is more than half of fifteen plus seven, which is fourteen and a half, so both invitations go out.
Example 2
A hundred is more than half of a hundred plus seven, so every member invites every other: three members with two others apiece.
Example 3
A single member has nobody else to invite, and nobody invites themselves.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def num_friend_requests(ages: list[int]) -> int:public int numFriendRequests(int[] ages)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.