Find an Instant-Runoff Winner without Modifying Ballots

Read the full interview experience this question came from →

Quick Overview

Implement instant-runoff elimination with immutable ranked ballots, enum candidates, and an explicit tie rule. Scale the calculation to millions of ballots by counting observed rankings and managing file I/O without factorial preallocation.

Find an Instant-Runoff Winner without Modifying Ballots

Company: Wise

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

Candidates are represented by enum values, and each ballot ranks candidates by preference. Repeatedly count each ballot for its highest-ranked remaining candidate, eliminate the least popular remaining candidate, and continue until one candidate remains. Return that candidate without changing the input ballots. ### Constraints and Clarifications Resolve elimination ties explicitly. For this practice interface, enum declaration order supplies stable distinct indices; among candidates tied for the smallest count, eliminate the one with the greatest index. This is a chosen normalization, not a reported tie policy. Assume a nonempty candidate list and that each ballot is a complete permutation of those candidates. If there are no ballots, the same tie rule still applies. A large-file follow-up has 3–15 candidates and millions of ballots; the file cannot be loaded entirely into memory. ### Example Candidates in enum order are A, B, C. Ballots are [A,B,C], [A,C,B], [B,A,C], [B,C,A], [C,A,B]. The first counts are A=2, B=2, C=1, so C is eliminated. Its ballot transfers to A, giving A=3 and B=2. B is eliminated and A wins. ### What a Strong Answer Covers Implement rounds and the tie rule without mutating ballots. Include candidates with zero votes in the minimum search. Then explain chunked file reading, aggregation of identical rankings, and the limits of enumerating every possible preference ordering. ### Follow-up Questions - How would you reduce repeated scans by tracking the current active preference for each ranking? - Why is allocating a count for every permutation problematic near 15 candidates? - What extra policy is required for incomplete or exhausted ballots?

Overview: Implement instant-runoff elimination with immutable ranked ballots, enum candidates, and an explicit tie rule. Scale the calculation to millions of ballots by counting observed rankings and managing file I/O without factorial preallocation.

Read the full Wise Software Engineer interview experience this question came from

Wise logo
Wise
Oct 23, 2026
mediumSoftware EngineerOnsiteCoding & Algorithms
0
0

Candidates are represented by enum values, and each ballot ranks candidates by preference. Repeatedly count each ballot for its highest-ranked remaining candidate, eliminate the least popular remaining candidate, and continue until one candidate remains. Return that candidate without changing the input ballots.

Constraints and Clarifications

Resolve elimination ties explicitly. For this practice interface, enum declaration order supplies stable distinct indices; among candidates tied for the smallest count, eliminate the one with the greatest index. This is a chosen normalization, not a reported tie policy. Assume a nonempty candidate list and that each ballot is a complete permutation of those candidates. If there are no ballots, the same tie rule still applies. A large-file follow-up has 3–15 candidates and millions of ballots; the file cannot be loaded entirely into memory.

Example

Candidates in enum order are A, B, C. Ballots are [A,B,C], [A,C,B], [B,A,C], [B,C,A], [C,A,B]. The first counts are A=2, B=2, C=1, so C is eliminated. Its ballot transfers to A, giving A=3 and B=2. B is eliminated and A wins.

What a Strong Answer Covers Guidance

Implement rounds and the tie rule without mutating ballots. Include candidates with zero votes in the minimum search. Then explain chunked file reading, aggregation of identical rankings, and the limits of enumerating every possible preference ordering.

Follow-up Questions Guidance

  • How would you reduce repeated scans by tracking the current active preference for each ranking?
  • Why is allocating a count for every permutation problematic near 15 candidates?
  • What extra policy is required for incomplete or exhausted ballots?