Count Unhappy Friends
Updated
Problem statement
Given n people, their preferences and their pairs, return how many people are unhappy.
preferences[x] lists every other person, from most to least preferred. pairs gives each person exactly one partner. Person x, paired with y, is unhappy if some person u, paired with v, meets both conditions: x prefers u over y, and u prefers x over v.
Function
unhappyFriends(n: int, preferences: int[][], pairs: int[][]) → intExamples
Example 1
n = 4preferences = [[1,2,3],[3,2,0],[3,1,0],[1,2,0]]pairs = [[0,1],[2,3]]return = 2People 1 and 3 each prefer the other over their own partner, so both are unhappy. Everyone else is paired with their first choice, so only these two are unhappy.
Constraints
2 <= n <= 500and n is even.- Each row of
preferenceslists every other person exactly once. - Every person is in exactly one pair of
pairs.
More Bloomberg LP Onsite Interview questions
- N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Top K Frequent WordsONSITE INTERVIEW · Seen Nov 2026
- Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Add Two Numbers IIPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Decode StringPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Minimum Replacements to Make Two Strings AnagramsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Currency Conversion RatePHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
Similar questions at other companies
- Random Dasher Set OperationsDoorDash · ONSITE INTERVIEWDoorDash interview questions
- Determine the Winner of Three-Card HandsOpenAI · PHONE SCREENOpenAI interview questions
- Logger Rate Limiter with Every-Arrival HistoryGoogle · PHONE SCREENGoogle interview questions
- Propagating Fraud DetectorAffirm · PHONE SCREEN · ONSITE INTERVIEWAffirm interview questions
- Asteroid CollisionSiemens · PHONE SCREEN
- Constant-Time Weighted Pick with an Alias TableEtched · PHONE SCREEN
- Order and Batch Open-Close LifecycleHudson River Trading · PHONE SCREENHudson River Trading interview questions
- Pins Violation Log QueriesPinterest · PHONE SCREENPinterest interview questions
- Billing Log with Undo and RedoReddit · PHONE SCREENReddit interview questions
- Deep Copy a Random-Pointer ListAmazon · ONSITE INTERVIEW
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)