PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Squarepoint

Maximize revenue from inventory sales

Last updated: Mar 29, 2026

Quick Overview

This question evaluates algorithmic problem-solving and optimization competencies focused on dynamic resource allocation, revenue maximization, and designing efficient solutions that scale with large n, m, and quantities.

  • medium
  • Squarepoint
  • Coding & Algorithms
  • Data Scientist

Maximize revenue from inventory sales

Company: Squarepoint

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Take-home Project

### Problem A store has `n` different products. For each product `i` (0-indexed), you are given an integer `quantity[i]` representing how many units of that product are currently in stock. The store will serve `m` customers. Each customer buys exactly one unit of some product, subject to availability (you cannot sell a product whose stock is 0). **Pricing rule:** - When a customer buys one unit of product `i`, the price they pay is equal to the **current** remaining stock of product `i` *before* the purchase. - After the purchase, the stock of product `i` decreases by 1 (i.e., `quantity[i]--`). - Thus, if product `i` has stock 5 when a customer arrives and they buy it, that customer pays 5, and the stock becomes 4 for future customers. The store can choose, for each customer, which product to sell (among those with positive stock) in order to maximize total revenue. If `m` is larger than the total number of units in stock, then at most the total stock many customers can be served; the remaining customers simply cannot buy anything. ### Input - An integer `n` – the number of different products. - An array `quantity` of length `n`, where `quantity[i]` is a non-negative integer representing the initial stock of product `i`. - An integer `m` – the number of customers, where each customer buys at most one unit as described. ### Output Return a single integer: the **maximum total revenue** the store can obtain by appropriately choosing which product to sell to each customer. You should design an efficient algorithm suitable for large `n`, `m`, and quantities. ### Example Suppose: - `n = 2` - `quantity = [2, 3]` - `m = 3` One optimal sequence of sales is: - Customer 1 buys from product 1 (stock 3) → pays 3, stock becomes `[2, 2]`. - Customer 2 buys from product 0 (stock 2) → pays 2, stock becomes `[1, 2]`. - Customer 3 buys from product 1 (stock 2) → pays 2, stock becomes `[1, 1]`. Total revenue = `3 + 2 + 2 = 7`, which is optimal. Implement a function that computes this maximum revenue.

Quick Answer: This question evaluates algorithmic problem-solving and optimization competencies focused on dynamic resource allocation, revenue maximization, and designing efficient solutions that scale with large n, m, and quantities.

Related Interview Questions

  • Implement EMA Crossovers and Root Solvers - Squarepoint (medium)
  • Solve two coding assessment tasks - Squarepoint (hard)
  • Parse payroll file and answer queries - Squarepoint (medium)
  • Maximize profit from one or many stock trades - Squarepoint (hard)
Squarepoint logo
Squarepoint
Dec 8, 2025, 7:33 PM
Data Scientist
Take-home Project
Coding & Algorithms
5
0

Problem

A store has n different products. For each product i (0-indexed), you are given an integer quantity[i] representing how many units of that product are currently in stock.

The store will serve m customers. Each customer buys exactly one unit of some product, subject to availability (you cannot sell a product whose stock is 0).

Pricing rule:

  • When a customer buys one unit of product i , the price they pay is equal to the current remaining stock of product i before the purchase.
  • After the purchase, the stock of product i decreases by 1 (i.e., quantity[i]-- ).
  • Thus, if product i has stock 5 when a customer arrives and they buy it, that customer pays 5, and the stock becomes 4 for future customers.

The store can choose, for each customer, which product to sell (among those with positive stock) in order to maximize total revenue.

If m is larger than the total number of units in stock, then at most the total stock many customers can be served; the remaining customers simply cannot buy anything.

Input

  • An integer n – the number of different products.
  • An array quantity of length n , where quantity[i] is a non-negative integer representing the initial stock of product i .
  • An integer m – the number of customers, where each customer buys at most one unit as described.

Output

Return a single integer: the maximum total revenue the store can obtain by appropriately choosing which product to sell to each customer.

You should design an efficient algorithm suitable for large n, m, and quantities.

Example

Suppose:

  • n = 2
  • quantity = [2, 3]
  • m = 3

One optimal sequence of sales is:

  • Customer 1 buys from product 1 (stock 3) → pays 3, stock becomes [2, 2] .
  • Customer 2 buys from product 0 (stock 2) → pays 2, stock becomes [1, 2] .
  • Customer 3 buys from product 1 (stock 2) → pays 2, stock becomes [1, 1] .

Total revenue = 3 + 2 + 2 = 7, which is optimal.

Implement a function that computes this maximum revenue.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Squarepoint•More Data Scientist•Squarepoint Data Scientist•Squarepoint Coding & Algorithms•Data Scientist 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.