Maximize Distinct Purchases Within Budget Constraints
TikTokData Scientist · Online AssessmentLast 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.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.