Katkat

Maximize Distinct Purchases Within Budget Constraints

TikTokData Scientist · Online Assessment

Last updated

This question evaluates understanding of selection and optimization under budget constraints, algorithmic efficiency, and the ability to implement correct logic for maximizing the number of distinct items purchased.

Scenario

Given a customer budget and a list of product prices, determine the maximum number of distinct products the customer can afford.

Question

Design an algorithm that lists the products a customer can purchase within their budget while maximizing the count of items bought.

Hints

Sort prices ascending, add items greedily until the running total would exceed the budget.