Preference List Majority Winner
Updated
Problem statement
Each row of preferences represents one voter and lists that voter's acceptable candidates from most preferred to least preferred.
Consider complete vote assignments in depth-first order: process voters from left to right, and for each voter try the candidates in that voter's listed order. A candidate wins an assignment when they receive strictly more than half of all votes.
Return the winner of the first assignment in this order that has a majority. Return -1 if no assignment can produce a majority.
Function
rankedChoiceWinner(preferences: int[][]) → intExamples
Example 1
preferences = [[1],[1],[2]]return = 1The only assignment gives candidate 1 two of the three votes, which is a strict majority.
Example 2
preferences = [[1],[1],[2],[2],[3,1]]return = 1The all-first-choice assignment has no majority. Trying the fifth voter's next choice gives candidate 1 three of five votes.
Example 3
preferences = [[1,2],[1,2],[2,1],[2,3],[3,1]]return = 1The first choices split 2-2-1. The earliest winning assignment keeps the first four choices and uses candidate 1 as the fifth voter's second choice.
Constraints
1 <= preferences.length <= 201 <= preferences[i].length <= 81 <= preferences[i][j] <= 1000000- Each voter's preference list contains distinct candidates.
- The product of all preference-list lengths is at most
1000000.
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
- Numeric Poker OperationsRippling · PHONE SCREENRippling interview questions
- All Long Subsequences Are Dictionary WordsGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Validate a Mahjong Hand PartitionDuolingo · PHONE SCREENDuolingo interview questions
- Maximum Unique Substring SplitThe Walt Disney Company · PHONE SCREENThe Walt Disney Company interview questions
- Sudoku Puzzle SolverConfluent · PHONE SCREEN · ONSITE INTERVIEWConfluent interview questions
- Optimal Account BalancingPinterest · PHONE SCREEN · ONSITE INTERVIEWPinterest interview questions
- Word Break IIAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Word Break IIWex · PHONE SCREEN
- Optimal Account BalancingSalesforce · PHONE SCREENSalesforce interview questions
- Sudoku SolverInMobi · PHONE SCREENInMobi interview questions
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)