PracHub
QuestionsLearningGuidesInterview Prep

Quick Overview

This question evaluates algorithm design and data-structure skills—frequency counting, hashing, and handling edge cases such as ties and a no-mode rule—within the coding and algorithms domain for data scientist roles.

  • medium
  • Amazon
  • Coding & Algorithms
  • Data Scientist

Compute array modes with ties and no-mode rule

Company: Amazon

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

Write a function that returns the mode(s) of an integer array. Requirements: if all values are unique, return an empty list (there is no mode); allow and return multiple modes, ordered by first occurrence in the input; run in O(n) expected time and O(u) extra space where u is the number of unique values. Follow-ups: 1) How would you support a streaming array with unknown length using O(u_window) space and emit current modes over a sliding window of size W? 2) How would you break ties deterministically in case-insensitive string data while preserving stable order? 3) Analyze worst-case time and space. Examples: [3,1,2,2,3] -> [3,2] (both appear twice); [1,2,3] -> []; [7,7,7] -> [7].

Quick Answer: This question evaluates algorithm design and data-structure skills—frequency counting, hashing, and handling edge cases such as ties and a no-mode rule—within the coding and algorithms domain for data scientist roles.

Return the mode values of an integer array. If every value is unique, return an empty list. If several values tie for highest frequency, return them in first-occurrence order.

Constraints

  • nums may be empty.
  • Return [] when the highest frequency is 1.
  • Multiple modes must preserve first occurrence in the input.

Examples

Input: ([3,1,2,2,3],)

Expected Output: [3, 2]

Explanation: 3 and 2 both occur twice and are ordered by first occurrence.

Input: ([1,2,3],)

Expected Output: []

Explanation: All values are unique, so there is no mode.

Hints

  1. Count frequencies and remember first-seen order.
  2. The no-mode rule applies only when every frequency is 1.
Last updated: Jun 27, 2026

Loading coding console...

PracHub

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

Product

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

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding 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.

Related Coding Questions

  • Schedule Priority Jobs with Cooldowns - Amazon (medium)
  • Find Paths Across a Weighted Binary Grid - Amazon (medium)
  • Implement Multi-Player Tic-Tac-Toe - Amazon (medium)
  • Compute Edit Distance - Amazon (medium)
  • Minimize Replacements So Equal Product Values Are Contiguous - Amazon (hard)