Count Centaur Friend Requests
Updated
Problem statement
A group of centaurs sign up for accounts and may send directed friend requests to one another. You are given their integer ages in ages.
A centaur with age x sends a request to a different centaur with age y only when all of these rules hold:
y >= x / 2 + 7, where the division is real-number division.y <= x.- If
x > 100, theny >= 100.
Count the total number of directed friend requests. Centaurs with the same age are still distinct people, and no centaur may send a request to themself.
Function
countCentaurFriendRequests(ages: int[]) → longExamples
Example 1
ages = [120,110]return = 1The 120-year-old centaur sends one request to the 110-year-old centaur. The reverse request is disallowed because the recipient would be older.
Example 2
ages = [120,110,99]return = 1The 99-year-old recipient is disallowed for both senders over 100, so only the request from age 120 to age 110 is sent.
Example 3
ages = [120,45,230,400,88,300,101]return = 4Exactly four ordered sender-recipient pairs satisfy every age rule.
Example 4
ages = [101,120,230,400,88,45,55,300]return = 6Counting valid ordered pairs across all eight distinct centaurs gives six requests.
Example 5
ages = [100,110,120]return = 3The valid requests are from age 110 to 100 and from age 120 to both 100 and 110.
Constraints
1 <= ages.length <= 2 * 10^5.1 <= ages[i] <= 10^9.- Each position in
agesrepresents a distinct centaur.
More Meta Phone Screen questions
- Convert a Sorted Linked List to a Balanced BSTPHONE SCREEN · Seen Nov 2026
- Fuzzy Word Lookup With One Misspelled LetterPHONE SCREEN · Seen Nov 2026
- Multi-Head Attention Forward PassPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Run-Length Encoded Vector Dot ProductPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Mutual-Friend RecommendationsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best Time to Buy and Sell StockPHONE SCREEN · Seen Nov 2026
- First Element Greater Than KPHONE SCREEN · Seen Nov 2026
- Count Events in Rolling Minute WindowsPHONE SCREEN · Seen Oct 2026
- Valid Word AbbreviationPHONE SCREEN · Seen Oct 2026
- Shortest Path in a Binary MatrixPHONE SCREEN · Seen Sep 2026
Similar questions at other companies
- Find All Pythagorean TripletsDell Technologies · PHONE SCREEN
- Sort a Quadratic-Transformed ArrayLinkedIn · PHONE SCREEN
- Count Winning Dice Face PairsGoogle · PHONE SCREEN
- Count Triples That Can Form a TriangleAdobe · PHONE SCREEN
- 3Sum SmallerSalesforce · ONSITE INTERVIEW
- Linear InterpolatorTwo Sigma · OA
- Merge Sorted Squares of Two ArraysWhatNot · PHONE SCREEN · ONSITE INTERVIEW
- 3SumAmazon · PHONE SCREEN
- Sort Ones, Twos, and Threes In PlaceAgoda · PHONE SCREEN · ONSITE INTERVIEW
- Adaptive Calibration ErrorOpenAI · PHONE SCREEN