PracHub
QuestionsPremiumCoachesLearningGuidesInterview 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.

Input: ([7,7,7],)

Expected Output: [7]

Explanation: A single repeated value is the only mode.

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

Expected Output: [-1, 2]

Explanation: Tied modes preserve first-seen order.

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 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.

Related Coding Questions

  • Implement Top-p (Nucleus) Sampling in NumPy - Amazon (medium)
  • Implement Multi-Head Attention from Scratch in NumPy - Amazon (medium)
  • Detect and Break a Cycle in a Singly Linked List - Amazon (medium)
  • Caesar Cipher with Translation-Table Optimization - Amazon (medium)
  • Minimum Drone Delivery Time on a Ring of Hubs - Amazon (medium)