Tap here to switch tabs
Problem
Submissions

Problem: Buy Two Chocolates

med
30 min
Try to solve the Buy Two Chocolates problem.

Statement

You are given an integer array prices representing the prices of different chocolates in a store, and an integer money representing the initial amount of money you have.

You must buy exactly 22 chocolates such that you do not end up in debt. To maximize the leftover money, you need to minimize the total cost of the two chosen chocolates.

Return the amount of money you will have remaining after purchasing two chocolates with the minimum total cost. If you cannot purchase 22 chocolates without going into debt, return money.

Constraints:

  • 2≤2 \leq prices.length ≤50\leq 50

  • 1≤1 \leq prices[i] ≤100\leq 100

  • 1≤1 \leq money ≤100\leq 100

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Buy Two Chocolates

med
30 min
Try to solve the Buy Two Chocolates problem.

Statement

You are given an integer array prices representing the prices of different chocolates in a store, and an integer money representing the initial amount of money you have.

You must buy exactly 22 chocolates such that you do not end up in debt. To maximize the leftover money, you need to minimize the total cost of the two chosen chocolates.

Return the amount of money you will have remaining after purchasing two chocolates with the minimum total cost. If you cannot purchase 22 chocolates without going into debt, return money.

Constraints:

  • 2≤2 \leq prices.length ≤50\leq 50

  • 1≤1 \leq prices[i] ≤100\leq 100

  • 1≤1 \leq money ≤100\leq 100