Spend a Budget Across Five Price Tiers
Updated
Problem statement
A travel app groups the places you can visit into five price tiers: 100, 50, 25, 10 and 5. Every place in a tier costs that tier's price, and each tier has as many places as you want.
Given budget, choose how many places of each tier to visit so that the total price is at most budget and the money left over is as small as possible.
Several plans can leave the same amount. Among them, pick the plan with the most places at price 100. If that still ties, pick the one with the most places at 50, then at 25, then at 10.
Return an array of five counts: the number of places at 100, 50, 25, 10 and 5, in that order.
Function
placesPerTier(budget: int) → int[]Examples
Example 1
budget = 1234return = [12,0,1,0,1]12 places at 100 cost 1200 and leave 34. 50 does not fit, one place at 25 leaves 9, 10 does not fit, and one place at 5 leaves 4. Every price is a multiple of 5, so no plan can leave less than 4.
Example 2
budget = 33return = [0,0,1,0,1]The smallest possible leftover is 3. Both 25 + 5 and 10 + 10 + 10 leave 3. The tie goes to the plan with more places at the higher price, so the answer is one place at 25 and one at 5.
Example 3
budget = 1985return = [19,1,1,1,0]19 places at 100 leave 85, then one at 50 leaves 35, one at 25 leaves 10, and one at 10 leaves 0. Nothing is left over.
Constraints
0 <= budget <= 10^6
More Expedia Onsite Interview questions
- Scramble StringONSITE INTERVIEW · Seen Sep 2026
- Smallest Sufficient TeamONSITE INTERVIEW · Seen Sep 2026
- Check Anagram Pairs Index by IndexONSITE INTERVIEW · Seen Oct 2025
- Fresh Oranges Left After Rotting StopsONSITE INTERVIEW · Seen Oct 2025
- Longest Increasing SubsequenceONSITE INTERVIEW · Seen Oct 2025
- Lowest Common Ancestor with Repeated and Missing ValuesONSITE INTERVIEW · Seen Oct 2025
- Shortest Substring with Exactly K OnesONSITE INTERVIEW · Seen Oct 2025
- Middle Element of a Linked ListONSITE INTERVIEW · Seen Nov 2024
- Minimum in a Rotated Sorted ArrayONSITE INTERVIEW · Seen Sep 2024
- Mirror Image Binary TreesONSITE INTERVIEW · Seen Sep 2024
Similar questions at other companies
- Maximum 69 NumberHSBC · ONSITE INTERVIEWHSBC interview questions
- Maximize the Chance of Selecting the Best CandidateGoogle · ONSITE INTERVIEWGoogle interview questions
- Fewest Bills and CoinsCapital One · ONSITE INTERVIEWCapital One interview questions
- Integer BreakAmazon · ONSITE INTERVIEW
- Maximum Bananas Delivered by a CamelStackAdapt · ONSITE INTERVIEWStackAdapt interview questions
- UCB1 Multi-Armed Bandit TraceWayfair · ONSITE INTERVIEWWayfair interview questions
- Reach a Target by Adding CoordinatesJP Morgan Chase · ONSITE INTERVIEWJP Morgan Chase interview questions
- Server InvestmentRippling · OARippling interview questions
- Maximum Three-Server Difficulty ScoreVisa · OAVisa interview questions
- Particle Moves to TargetCresta · OACresta interview questions
Expedia interview experiences
- Expedia Intern Final Round in 2021: 28 Experiences (Part 4 of 6)
- Expedia Intern Finals Before 2020: 14 Experiences (Part 6 of 6)
- Expedia Intern Final Round in 2020: 24 Experiences (Part 5 of 6)
- Expedia Intern Final Round in 2022: 15 Experiences (Part 3 of 6)
- Expedia Intern Final Round in 2023: 17 Experiences (Part 2 of 6)
- Expedia SWE Intern Final Round: 126 Experiences (Part 1 of 6)