Election District Budget Allocation Analysis
Updated
Problem statement
Two campaigns split their money across districts districts. Each district gets a whole number of funds, which can be zero. Your funds must add up to exactly ownFunds. The opponent's funds must add up to exactly opponentFunds. In each district you win if you put in more, lose if you put in less, and tie if you put in the same amount. You win the election exactly when you win more districts than you lose. Tied districts are ignored.
The opponent's allocation is random. The opponent model tells you how:
opponentModel = 0: every allocation of the opponent's budget across the districts is equally likely.opponentModel = 1: the opponent is as balanced as possible. Write its budget asq * districts + r. Exactlyrdistricts getq+1funds and the rest getq. Every different choice of which districts get the larger amount is equally likely.
Complete analyzeElection(districts, ownFunds, opponentFunds, opponentModel). Return an array of 5 + 2 * districts signed 64-bit integers, in this order:
- The total number of possible opponent allocations under the chosen model.
- The largest number of those allocations that one of your allocations can beat, using your exact budget.
- The smallest number of those allocations that one of your allocations can beat, using your exact budget.
- The smallest own budget that gives some allocation a positive chance of winning against a balanced opponent with the given
opponentFunds. This does not depend on the chosen model. - The smallest balanced opponent budget that makes winning impossible for every own allocation that adds up to the given
ownFunds. This does not depend on the chosen model. - The
districtsentries of a best allocation, then thedistrictsentries of a worst allocation.
If several allocations are equally good as the best, or equally bad as the worst, pick the lexicographically smallest one. The best and worst probabilities are the matching counts divided by the total number of opponent allocations. A positive chance means at least one possible opponent allocation can be beaten. It does not mean you are sure to win.
Function
analyzeElection(districts: int, ownFunds: int, opponentFunds: int, opponentModel: int) → long[]Examples
Example 1
districts = 3ownFunds = 4opponentFunds = 4opponentModel = 0return = [15,5,0,4,5,1,1,2,0,0,4]The opponent has 15 possible allocations. The lexicographically smallest best allocation for you is [1,1,2], which wins with probability 5/15. The worst is [0,0,4], which never wins. Against balanced opponents, the smallest own budget with a chance is 4. For own budget 4, the first opponent budget that blocks every allocation is 5.
Example 2
districts = 8ownFunds = 9opponentFunds = 9opponentModel = 1return = [8,3,0,9,12,0,0,0,1,2,2,2,2,0,0,0,0,0,0,0,9]The opponent has one district with 2 funds and seven with 1, giving 8 possible vectors. The best own allocation is [0,0,0,1,2,2,2,2]: it wins when the opponent puts its 2 in one of your three zero districts, so the probability is 3/8. The minimum own budget with positive chance is 9, rather than 10; tied districts make a majority of all eight districts unnecessary. A balanced opponent budget of 12 blocks every own allocation of budget 9.
Example 3
districts = 1ownFunds = 0opponentFunds = 0opponentModel = 0return = [1,0,0,1,0,0,0]Both campaigns allocate zero, so the only district ties and neither allocation wins. One own fund would beat a balanced zero-budget opponent. An own budget of zero is already blocked by opponent budget zero.
Example 4
districts = 1ownFunds = 2opponentFunds = 1opponentModel = 1return = [1,1,1,2,2,2,2]In one district, the unique own allocation [2] beats the unique opponent allocation [1]. Both best and worst therefore win. The minimum winning own budget and the first blocking opponent budget are both 2.
Constraints
1 <= districts <= 8,0 <= ownFunds <= 12, and0 <= opponentFunds <= 30.opponentModelis0or1. For model0, alsodistricts <= 4, so you can list every allocation directly.- Districts are labeled. Opponent allocations that are permutations of each other count separately, unless their full vectors are identical.
- The budget thresholds in the output may be larger than the input budget limits. Use exact integer counts, with no modulus and no rounding of probabilities.
More IMC Trading Phone Screen questions
- Uniform Variables: Smaller Below Larger SquaredPHONE SCREEN · Seen Mar 2026
- Combination Sum with Unlimited ReusePHONE SCREEN · Seen Dec 2025
- Valid Range of a Three-Outcome Probability ParameterPHONE SCREEN · Seen Dec 2025
- Expected Fishing CatchPHONE SCREEN · Seen Dec 2025
- Count Routes Through a City GridPHONE SCREEN · Seen Nov 2024
- Expected City Arrival and Return DaysPHONE SCREEN · Seen Nov 2024
- Stationary City Population SharesPHONE SCREEN · Seen Nov 2024
- Maximum Falling Path SumPHONE SCREEN · Seen Nov 2024
- Trading Profit Percentage ChangePHONE SCREEN · Seen Feb 2024
- Poker Suit Expected ProfitPHONE SCREEN · Seen Sep 2023
Similar questions at other companies
- Count Clean Attendance LogsRippling · PHONE SCREENRippling interview questions
- Biased Coin: Probability of Exactly h HeadsAkuna Capital · PHONE SCREENAkuna Capital interview questions
- Probability of Consecutive HeadsSquarepoint Capital · PHONE SCREENSquarepoint Capital interview questions
- Median of Uniform Draws in an IntervalSusquehanna International Group (SIG) · PHONE SCREENSusquehanna International Group (SIG) interview questions
- Heads in Fair Coin FlipsJane Street · PHONE SCREENJane Street interview questions
- Count Array DerangementsInMobi · PHONE SCREENInMobi interview questions
- Count Nondecreasing Digit-Sum ArraysMicrosoft · OAMicrosoft interview questions
- Stable Workload Redistribution TreesTower Research Capital · OA
- Count Valid A-B-C Sequences Under a Modulo-Four RuleInfosys · OAInfosys interview questions
- Count Permutations Without Three Equal Parities in a RowGoogle · OAGoogle interview questions