FastPrepMost Voted Candidate
Problems/Most Voted Candidate

Most Voted Candidate

Expedia logoExpedia● EasyINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: An entry from an Expedia Group SDE intern process names this task in its first video-call interview, on December 4, 2020.

The entry gives only the title. A separate card for that title gives the rule, with ties going to the name that is first in dictionary order, and limits of 1,000 votes and 20 characters per name. Its samples use capitalized names, but neither text fixes which characters a name may use. Here, each name is one capital letter followed by lowercase letters, so dictionary order is plain letter order. The function takes one list of votes instead of several test cases.

Our version is about 95% the same as the reported question.

In an election, every vote is the name of one candidate. You are given the votes as an array votes, where votes[i] is the name written on vote i. Two votes are for the same candidate exactly when their names are equal.

Return the name of the candidate with the most votes. If several candidates are tied for the most votes, return the tied name that comes first in dictionary order.

Dictionary order compares two names letter by letter from the left. At the first position where they differ, the name with the earlier letter comes first. If one name is a prefix of the other, the shorter name comes first (so "Ann" comes before "Anna").

Function

electionWinner(votes: String[]) → String

Examples

Example 1

votes = ["Maya","Leo","Maya","Iris","Leo","Maya"]return = "Maya"

Maya has 3 votes, Leo has 2 and Iris has 1. Maya has the most votes.

Example 2

votes = ["Omar","Bea","Omar","Zoe","Bea"]return = "Bea"

Omar and Bea both have 2 votes, and Zoe has 1. Omar and Bea are tied, and Bea comes first in dictionary order, so the answer is Bea, even though Omar got the first vote.

Example 3

votes = ["Anna","Ann","Anna","Ann","Ken"]return = "Ann"

Anna and Ann both have 2 votes. Ann is a prefix of Anna, and a shorter name that is a prefix of a longer one comes first, so the answer is Ann.

Constraints

  • 1 <= votes.length <= 1000
  • 1 <= votes[i].length <= 20
  • Each name is one uppercase English letter followed by zero or more lowercase English letters.

More Expedia Onsite Interview questions

  • Scramble StringONSITE INTERVIEW · Seen Sep 2026
  • Smallest Sufficient TeamONSITE INTERVIEW · Seen Sep 2026
  • Check Anagram Pairs Index by IndexONSITE INTERVIEW · Seen Oct 2025
  • Fresh Oranges Left After Rotting StopsONSITE INTERVIEW · Seen Oct 2025
  • Longest Increasing SubsequenceONSITE INTERVIEW · Seen Oct 2025
  • Lowest Common Ancestor with Repeated and Missing ValuesONSITE INTERVIEW · Seen Oct 2025
  • Shortest Substring with Exactly K OnesONSITE INTERVIEW · Seen Oct 2025
  • Middle Element of a Linked ListONSITE INTERVIEW · Seen Nov 2024
  • Minimum in a Rotated Sorted ArrayONSITE INTERVIEW · Seen Sep 2024
  • Mirror Image Binary TreesONSITE INTERVIEW · Seen Sep 2024

Similar questions at other companies

  • Map and Accumulate Learning QueriesPalantir · ONSITE INTERVIEWPalantir interview questions
  • Filter Anagrams of a TargetMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Deduplicate Logs: Keep FirstGoogle · ONSITE INTERVIEWGoogle interview questions
  • Loyal Customers by Two-Day Product VarietyAmazon · ONSITE INTERVIEW
  • Count Word FrequenciesBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
  • List Each Name Once, AlphabeticallyDocuSign · ONSITE INTERVIEWDocuSign interview questions
  • Process Shopping Records, Promotions, and Display OrderInstacart · PHONE SCREEN · ONSITE INTERVIEWInstacart interview questions
  • Deep Merge with a Conflict ResolverAutodesk · ONSITE INTERVIEWAutodesk interview questions
  • Group Duplicate Files by ContentPostman · ONSITE INTERVIEWPostman interview questions
  • Group AnagramsGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions

Expedia interview experiences

  • Expedia Intern Final Round in 2021: 28 Experiences (Part 4 of 6)
  • Expedia Intern Finals Before 2020: 14 Experiences (Part 6 of 6)
  • Expedia Intern Final Round in 2020: 24 Experiences (Part 5 of 6)
  • Expedia Intern Final Round in 2022: 15 Experiences (Part 3 of 6)
  • Expedia Intern Final Round in 2023: 17 Experiences (Part 2 of 6)
  • Expedia SWE Intern Final Round: 126 Experiences (Part 1 of 6)
All Expedia interview questionsSee Expedia hiring insights
Saved
class Solution {
    public String electionWinner(String[] votes) {
        // Write your code here.
    }
}
Checking account…