Friend Requests by Age
Updated
Problem statement
Each value in ages is one person's age. A person of age A sends a directed friend request to a different person of age B exactly when both conditions hold:
B > 0.5 * A + 7.B <= A.
Return the total number of directed friend requests. People of the same age may request each other, but nobody may request themself.
Function
numFriendRequests(ages: int[]) → intExamples
Example 1
ages = [16,16]return = 2Each sixteen-year-old sends one request to the other.
Example 2
ages = [16,17,18]return = 2The seventeen-year-old may request the sixteen-year-old, and the eighteen-year-old may request the seventeen-year-old.
Example 3
ages = [20,30,100,110,120]return = 3The valid directed requests are 110 -> 100, 120 -> 110, and 120 -> 100.
Constraints
1 <= ages.length <= 20000.1 <= ages[i] <= 120.
More Bloomberg LP Phone Screen questions
- Pascal's TrianglePHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Valid Triangle NumberPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Collatz Conjecture with Shared MemoizationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Fewest Coins CombinationPHONE SCREEN · Seen Nov 2026
- Recommend Films from Viewers Who Watched Everything You DidPHONE SCREEN · Seen Nov 2026
- Track New Values in Sorted OrderPHONE SCREEN · Seen Nov 2026
- Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Hash Partition OffsetsNVIDIA · PHONE SCREENNVIDIA interview questions
- Count Non-Overlapping Pairs of Rectangles That Sum to KWisdomAI · PHONE SCREEN
- Peak Chat Load Across AgentsCresta · PHONE SCREENCresta interview questions
- Trapping Rain WaterGoldman Sachs · PHONE SCREENGoldman Sachs interview questions
- Apply Operations to Make a String EmptyFlexport · PHONE SCREENFlexport interview questions
- Find Valid SET Card TriplesSnowflake · OA · PHONE SCREENSnowflake interview questions
- Best Improvement Period of at Least K IntervalsAmazon · PHONE SCREEN
- Majority Labels over Audio IntervalsNooks · PHONE SCREEN
- Random Pick with Weight Using Recorded DrawsGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Maximum Sum Desirable SubarrayGroww · PHONE SCREEN
Bloomberg LP interview experiences
- Bloomberg AI-Assisted Coding Round, All Levels: 14 Experiences
- Bloomberg SWE Intern Interview Questions: 68 Questions
- Bloomberg Interview Questions, Level Not Reported: 65 Questions
- Bloomberg Experienced Design & More: 126 Questions (Part 2 of 2)
- Bloomberg Experienced SWE Interviews: 167 Questions (Part 1 of 2)
- Bloomberg New Grad Coding Questions: 121 Questions (Part 2 of 2)