Count Winning Electoral-State Coalitions
Updated
Problem statement
Each positive integer in electoralVotes is one state's electoral-vote count. A coalition wins when its total is strictly more than half of all votes.
Return the number of subsets of states that win. The empty subset is included in consideration but cannot win. States with equal vote counts remain distinct.
Return the exact count as a signed 64-bit integer.
Function
countWinningCoalitions(electoralVotes: int[]) → longExamples
Example 1
electoralVotes = [3,2,1]return = 3Total votes are 6; winning subsets are {3,2}, {3,1}, and {3,2,1}.
Example 2
electoralVotes = [1,1,1]return = 4Any two states or all three states exceed half of 3.
Example 3
electoralVotes = []return = 0No coalition can win without states.
Example 4
electoralVotes = [1,3,4]return = 3The total is 8, so a winning subset needs more than 4 votes. The subsets {1,4}, {3,4} and {1,3,4} have 5, 7 and 8 votes. The subsets {4} and {1,3} have exactly 4 votes, which is not more than half, so the answer is 3.
Constraints
0 <= electoralVotes.length <= 40.1 <= electoralVotes[i] <= 1000.- The answer fits a signed 64-bit integer.
More Google Onsite Interview questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
- Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
- Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
- Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Coin Change IIApple · PHONE SCREEN · ONSITE INTERVIEWApple interview questions
- Count Strictly Increasing Subsequences of Length 3IBM · OAIBM interview questions
- Winning Draws for a Mahjong HandZip · PHONE SCREENZip interview questions
- Optimize Discount Selection Under a Point BudgetPalantir · OAPalantir interview questions
- Pressure-Isolation Shutdown OrderIntuit · OAIntuit interview questions
- Count Good SubsequencesFlexport · OAFlexport interview questions
- Sum of Compressed Number for All SubarraysWells Fargo · OAWells Fargo interview questions
- Count Perfect BreaksAtlassian · OAAtlassian interview questions
- Assign Escalations to TeamsAmazon · ONSITE INTERVIEW
- Count Subsets With a Target SumSafe Security · ONSITE INTERVIEW