PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Amazon

Find top-k lottery winners by spending

Last updated: May 27, 2026

Quick Overview

This question evaluates skills in selection and ordering of numeric-keyed records, covering concepts such as order statistics, deterministic tie-breaking, and time and space complexity analysis.

  • medium
  • Amazon
  • Coding & Algorithms
  • Software Engineer

Find top-k lottery winners by spending

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are building a lottery system where each user’s chance of winning is **linearly proportional** to how much they spent (e.g., user with spend `s` has weight `s`). Given: - An array of participants, each with a unique `user_id` and a non-negative integer `spend`. - An integer `k`. Task: - Return the **`k` users with the highest winning probability**, i.e., the `k` users with the largest `spend` values. Clarifications to handle: - If `k` is greater than the number of users, return all users. - Define how to break ties (e.g., by `user_id` ascending) and keep it consistent. - Discuss time and space complexity of your approach. Example: - Input: `[(A, 10), (B, 5), (C, 10), (D, 1)], k=2` - Output (one valid): `[A, C]` (tie broken deterministically)

Quick Answer: This question evaluates skills in selection and ordering of numeric-keyed records, covering concepts such as order statistics, deterministic tie-breaking, and time and space complexity analysis.

Related Interview Questions

  • Implement Datacenter Router Commands - Amazon (hard)
  • Implement Event Filtering and Queue Routing - Amazon (medium)
  • Determine if all courses can be completed - Amazon (medium)
  • Replace Delimited Tokens in a String - Amazon (medium)
  • Minimize Circular Redistribution Cost - Amazon (medium)
Amazon logo
Amazon
Jan 1, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
6
0
Loading...

You are building a lottery system where each user’s chance of winning is linearly proportional to how much they spent (e.g., user with spend s has weight s).

Given:

  • An array of participants, each with a unique user_id and a non-negative integer spend .
  • An integer k .

Task:

  • Return the k users with the highest winning probability , i.e., the k users with the largest spend values.

Clarifications to handle:

  • If k is greater than the number of users, return all users.
  • Define how to break ties (e.g., by user_id ascending) and keep it consistent.
  • Discuss time and space complexity of your approach.

Example:

  • Input: [(A, 10), (B, 5), (C, 10), (D, 1)], k=2
  • Output (one valid): [A, C] (tie broken deterministically)

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Amazon•More Software Engineer•Amazon Software Engineer•Amazon Coding & Algorithms•Software Engineer Coding & Algorithms
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.