Practice Closest Dessert Cost
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Choose exactly one base from baseCosts and zero, one, or two portions of each topping in toppingCosts. Return the achievable total cost nearest target. If two different costs are equally close, return the smaller cost.
Source: Closest Dessert Cost on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
baseCosts = [1,7], toppingCosts = [3,4], target = 10
Output
10
# Example 2
Input
baseCosts = [2,3], toppingCosts = [4,5,100], target = 18
Output
17
# Example 3
Input
baseCosts = [3,10], toppingCosts = [2,5], target = 9
Output
8
Constraints
n == baseCosts.length
m == toppingCosts.length
1 <= n, m <= 10
1 <= baseCosts[i], toppingCosts[i] <= 10^4
1 <= target <= 10^4
Related LeetCode Problems
Practice more problems similar to Closest Dessert Cost.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.