Problem · Math
Fair Electoral Vote Apportionment
Learn this problemProblem statement
Given nonnegative state populations and a nonnegative total number of votes, allocate every vote proportionally using the Hamilton largest-remainder method.
Function
allocateVotes(populations: int[], totalVotes: int) → int[]Examples
Example 1
populations = [100,200,300]totalVotes = 10return = [2,3,5]The largest remainder gives the final vote to state zero.
Example 2
populations = [1,1,1]totalVotes = 2return = [1,1,0]Equal remainders are resolved by smaller index.
Constraints
1 <= populations.length <= 10000- The population sum is positive.
- Products fit in signed 64-bit integers.