PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates familiarity with hash-table–based counting, efficient update and lookup operations, handling of ties with a deterministic tie-break rule, and reasoning about edge cases like unseen names or no votes.

  • medium
  • Ziprecruiter
  • Coding & Algorithms
  • Software Engineer

Design a voting counter for restaurants

Company: Ziprecruiter

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

You are building an in-memory voting component for a lunch poll. ## Task Design and implement a hash-table–backed data structure that supports collecting votes for restaurant names and reporting the most popular restaurant(s). ## Requirements - Each vote is a string `restaurantName`. - You must maintain vote counts as votes arrive. - Support these operations: 1. `vote(restaurantName)`: record one vote for the restaurant. 2. `getCount(restaurantName) -> int`: return the current vote count (0 if never seen). 3. `getWinner() -> string`: return the restaurant with the highest vote count. - If there is a tie, return the lexicographically smallest name (or clearly state and implement a deterministic tie-break rule). ## Constraints (assume) - Up to `N` total votes, where `N` can be large (e.g., 10^5–10^6). - Restaurant names can repeat and may include spaces. - Aim for near O(1) average time per `vote`/`getCount` using hashing. ## What to discuss - Data structures used and why. - Time and space complexity. - Edge cases: no votes yet, ties, unseen restaurant names.

Quick Answer: This question evaluates familiarity with hash-table–based counting, efficient update and lookup operations, handling of ties with a deterministic tie-break rule, and reasoning about edge cases like unseen names or no votes.

Process vote/getCount/getWinner operations. Winner is highest count, lexicographically smallest on ties.

Constraints

  • Inputs are Python literals matching the function signature.
  • Return a deterministic exact-match value.

Examples

Input: ([['getWinner'], ['vote','Sushi'], ['vote','Taco'], ['vote','Taco'], ['getWinner'], ['getCount','Sushi']],)

Expected Output: [None, None, None, None, 'Taco', 1]

Explanation: Votes and count.

Input: ([['vote','B'], ['vote','A'], ['getWinner']],)

Expected Output: [None, None, 'A']

Explanation: Tie breaks lexicographically.

Input: ([['getCount','None']],)

Expected Output: [0]

Explanation: Unseen count.

Hints

  1. Choose a representation that makes the requested operation direct.
  2. Handle empty inputs and boundary cases first.
Last updated: Jun 27, 2026

Related Coding Questions

  • Find Neighboring Records by Identifier - Ziprecruiter (easy)
  • Implement an in-memory storage with TTL and scans - Ziprecruiter (medium)

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.