FastPrepElection District Budget Allocation Analysis
Problems/Election District Budget Allocation Analysis

Election District Budget Allocation Analysis

IMC Trading logoIMC Trading● HardNEW GRADPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an IMC Trading new grad phone screen. The election game asks for the best and worst allocations, symmetry, winning chances, and the least budgets. Our task covers those questions and is about 90% the same. We spell out the random rules and combine the follow-up questions into one fixed list of results. The reported winning rule compares won and lost districts. Ties do not need a strict majority of all districts.

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 as q * districts + r. Exactly r districts get q+1 funds and the rest get q. 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:

  1. The total number of possible opponent allocations under the chosen model.
  2. The largest number of those allocations that one of your allocations can beat, using your exact budget.
  3. The smallest number of those allocations that one of your allocations can beat, using your exact budget.
  4. 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.
  5. 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.
  6. The districts entries of a best allocation, then the districts entries 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, and 0 <= opponentFunds <= 30.
  • opponentModel is 0 or 1. For model 0, also districts <= 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

IMC Trading interview experiences

  • IMC Trading OA: What It Tests (2026)
  • IMC Trading SWE OA and Video: 18 Experiences (Part 3 of 3)
  • IMC Trading SWE OA Questions: 22 Experiences (Part 2 of 3)
  • IMC SWE New Grad OA and Interviews: 58 Experiences (Part 1 of 3)
All IMC Trading interview questionsSee IMC Trading hiring insights
Saved
class Solution {
    public long[] analyzeElection(int districts, int ownFunds, int opponentFunds, int opponentModel) {
        // Write your solution here.
    }
}
Checking account…