← Coursera Interview Insights

Coursera·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Coursera software engineer interview with a simulation problem that looks straightforward until you actually try to implement it cleanly. The IRV question had enough edge cases to keep things interesting for a while.

Questions Asked (1)

Q1

Given a list of ranked ballots where each ballot is an ordered list of candidate names, implement Instant Runoff Voting: each round count only the top still-active candidate per ballot, declare a winner if someone exceeds 50% of votes, otherwise eliminate the candidate with the fewest votes (breaking ties by eliminating the lexicographically largest name), and return the final winner.

Algorithms & Data Structures
Author's notes

My first instinct was to mutate the ballots as candidates got eliminated and I wasted a few minutes going down that path before realizing it was a mess.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the problem and edge cases, then outline a round-based simulation where each round counts first-choice votes among active candidates, checks for a majority, and eliminates the lowest candidate with tie-breaking by lexicographically largest name. Discuss data structures and complexity before coding, and consider optimizations like precomputing ballot rankings or using a priority queue for elimination.

Pro tip: Mention that you can precompute each ballot's ranking as a list of candidate indices and maintain a pointer to the current top active candidate, reducing per-round counting to O(B) and overall complexity to O(B * C) in the worst case.

1. Clarify requirements and edge cases

Ask about input constraints (number of ballots, candidates), tie-breaking rules, and behavior when all candidates tie or when a ballot has no active candidates. Confirm that majority means >50% of active votes.

2. Design the algorithm

Simulate rounds: count first-choice votes among active candidates, check for a majority winner, else eliminate the candidate with the fewest votes (tie-break: lexicographically largest name). Repeat until a winner is found.

3. Choose data structures and optimize

Use a set for active candidates, a map for vote counts, and precompute ballot rankings to quickly find the top active candidate per ballot. Consider a priority queue for efficient elimination.

4. Analyze complexity and test

Discuss time and space complexity (e.g., O(B * C) time, O(B * C) space). Walk through edge cases: single candidate, all ballots identical, ties, and empty ballots.

5. Code and verify

Implement the solution cleanly, using helper functions for counting and elimination. Test with provided examples and additional edge cases to ensure correctness.

Key Points to Mention

  • Round-based simulation with active candidate tracking
  • Majority threshold: strictly greater than 50% of active votes
  • Tie-breaking rule: eliminate lexicographically largest name among those with fewest votes
  • Efficiency: precompute ballot rankings and use pointers to avoid rescanning entire ballots each round
  • Edge cases: single candidate, all candidates tied, ballots with no active candidates
  • Complexity analysis: O(B * C) time and O(B * C) space, where B is number of ballots and C is number of candidates

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.