PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates a candidate's understanding of greedy and resource-allocation strategies along with combinatorial reasoning to maximize operations under discrete constraints.

  • medium
  • Amazon
  • Coding & Algorithms
  • Software Engineer

Compute maximum distinct-product pickup days

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Take-home Project

##### Question Given an array of positive integers representing quantities of different products, on day i (starting from 1) you must pick exactly i distinct products, taking one unit from each chosen product. After each pick the chosen products' quantities decrease by 1 and cannot go below 0. Compute the maximum number of days the process can continue.

Quick Answer: This question evaluates a candidate's understanding of greedy and resource-allocation strategies along with combinatorial reasoning to maximize operations under discrete constraints.

You are given an array quantities of positive integers, where quantities[i] is the number of units of product i. Starting from day 1, on day d you must pick exactly d distinct products (if possible), taking one unit from each picked product. After each day's picks, the chosen products' quantities each decrease by 1 and never go below 0. You may choose which products to pick each day to maximize the number of days. Return the maximum number of consecutive days (starting from day 1) the process can continue.

Constraints

  • 1 <= len(quantities) <= 2e5
  • 1 <= quantities[i] <= 1e9
  • Sum of quantities <= 2e5
  • Answer is at most len(quantities)

Hints

  1. On day d you need at least d products with positive remaining quantities.
  2. Greedily take one unit from the d largest available quantities each day.
  3. A max-heap efficiently retrieves the largest counts at each step.
  4. Stop when the heap has fewer than d elements.
Last updated: Mar 29, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,500+ 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

  • Find a Maximum-Sum Window in a Sparse Array - Amazon (hard)
  • Find Two-Word Compound Words - Amazon (hard)
  • Unify Stock-Trading Profit Variants - Amazon (easy)
  • Implement Regular Expression Matching - Amazon (easy)
  • Minimum Path Length Through a Grid With One Allowed Cell Conversion - Amazon (medium)