Tap here to switch tabs
Problem
Submissions

Problem: Closest Dessert Cost

med
30 min
Try to solve the Closest Dessert Cost problem.

Statement

You want to make a dessert and are given two integer arrays, baseCosts and toppingCosts, as well as an integer target.

To prepare the dessert, you must follow these rules:

  • You must choose exactly 11 base from baseCosts.

  • You may choose 00, 11, or 22 servings of each topping from toppingCosts.

Return the total cost of the dessert that is closest to target. If there is a tie, return the lower cost.

Constraints:

  • n ==== baseCosts.length

  • m ==== toppingCosts.length

  • 1≤1 \leq n, m ≤10\leq 10

  • 1≤1 \leq baseCosts[i], toppingCosts[i] ≤104\leq 10^4

  • 1≤1 \leq target ≤104\leq 10^4

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Closest Dessert Cost

med
30 min
Try to solve the Closest Dessert Cost problem.

Statement

You want to make a dessert and are given two integer arrays, baseCosts and toppingCosts, as well as an integer target.

To prepare the dessert, you must follow these rules:

  • You must choose exactly 11 base from baseCosts.

  • You may choose 00, 11, or 22 servings of each topping from toppingCosts.

Return the total cost of the dessert that is closest to target. If there is a tie, return the lower cost.

Constraints:

  • n ==== baseCosts.length

  • m ==== toppingCosts.length

  • 1≤1 \leq n, m ≤10\leq 10

  • 1≤1 \leq baseCosts[i], toppingCosts[i] ≤104\leq 10^4

  • 1≤1 \leq target ≤104\leq 10^4