← Coursera Interview Insights

Coursera·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jul 2026

Summary

Coding screen for a software engineer role at Coursera, centered on an election simulation problem. Two parts to the same problem, and the second one had enough edge cases to keep me busy for a while.

Questions Asked (2)

Q1

Given a list of ranked ballots, implement a simple plurality voting system that returns the candidate with the most first-choice votes, breaking ties by lexicographic order.

Algorithms & Data Structures
Author's notes

Pretty straightforward once you realize you only look at the first element of each ballot.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the input format and edge cases, then outline a hash map approach to tally first-choice votes. After tallying, find the maximum count and collect all candidates with that count, returning the lexicographically smallest among them.

Pro tip: Mention that you'd handle empty ballots or no candidates gracefully, and discuss how the solution scales if the number of candidates or ballots grows large.

1. Clarify requirements and edge cases

Ask about input format (e.g., list of lists of strings), tie-breaking rules, and what to return if there are no ballots. Confirm that lexicographic order is based on candidate names.

2. Design the vote tallying

Use a hash map (dictionary) to count first-choice votes for each candidate. Iterate through each ballot and increment the count for the first candidate.

3. Determine the winner

Find the maximum vote count. Collect all candidates with that count, then return the lexicographically smallest candidate name.

4. Analyze complexity and test

State time complexity O(N) where N is number of ballots, and space O(C) for C candidates. Walk through a small example and edge cases like ties and empty input.

Key Points to Mention

  • Hash map for efficient vote counting
  • Tie-breaking by lexicographic order using min() or sorting
  • Edge cases: empty ballot list, no candidates, all candidates tied
  • Time and space complexity analysis
  • Potential follow-up: what if ballots have multiple choices? (e.g., instant runoff)
  • Code clarity and modularity (separate tallying and winner selection)

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

Q2

Using the same ballot input, implement instant-runoff voting: repeatedly eliminate the candidate with the fewest votes each round until someone crosses 50%, handling ties by eliminating the lexicographically largest candidate.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

This is where it got messy.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the input format and tie-breaking rules, then outline a round-by-round simulation where you tally first-choice votes, check for a majority, and eliminate the candidate with the fewest votes (breaking ties by removing the lexicographically largest). Emphasize efficiency by using a data structure that supports fast vote redistribution, and discuss time/space complexity.

Pro tip: Mention that you would validate the input and handle edge cases like all candidates tied or a single candidate, and that you can optimize by precomputing ballot rankings to avoid re-scanning all ballots each round.

1. Clarify requirements and edge cases

Confirm the ballot input format (e.g., list of ranked candidate lists), the majority threshold (strictly >50% of active votes), and tie-breaking rule (eliminate lexicographically largest among those with fewest votes). Ask about empty ballots, exhausted votes, and whether all candidates must be ranked.

2. Design the simulation loop

Outline a loop that runs until a candidate exceeds 50% or only one remains. In each round, tally first-choice votes from active ballots, check for a winner, and if not, identify the candidate(s) with the fewest votes and eliminate the lexicographically largest among them.

3. Choose data structures for efficiency

Use a hash map to count votes per candidate and a list of active candidates. For each ballot, maintain a pointer to the current top choice; when a candidate is eliminated, advance the pointer to the next non-eliminated candidate. This avoids re-scanning entire ballots each round.

4. Implement and test with examples

Write pseudocode or code for the simulation, ensuring tie-breaking is correctly applied. Test with simple cases (single candidate, majority in first round) and complex cases (multiple rounds, ties, exhausted ballots).

5. Analyze complexity and trade-offs

Discuss time complexity: O(R * B) naive vs. O(B + R * C) with pointers, where R is rounds, B ballots, C candidates. Mention space complexity O(B + C). Trade-offs: simplicity vs. performance, and how to handle large inputs.

Key Points to Mention

  • Majority threshold: strictly more than 50% of active (non-exhausted) votes.
  • Tie-breaking: eliminate the lexicographically largest candidate among those with the fewest votes.
  • Handling exhausted ballots: if a ballot has no remaining candidates, it is removed from the active count.
  • Efficiency: use a pointer per ballot to track current top choice, avoiding full re-scan each round.
  • Edge cases: all candidates tied, single candidate, empty ballots, and candidates with zero votes.
  • Complexity: time O(B * R) naive, O(B + R * C) optimized; space O(B + C).

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