File size: 1,977 Bytes
4097b71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
{
  "id": 2756,
  "name": "buy-two-chocolates",
  "difficulty": "Easy",
  "link": "https://leetcode.com/problems/buy-two-chocolates/",
  "date": "2023-05-13",
  "task_description": "You are given an integer array `prices` representing the prices of various chocolates in a store. You are also given a single integer `money`, which represents your initial amount of money. You must buy **exactly** two chocolates in such a way that you still have some **non-negative** leftover money. You would like to minimize the sum of the prices of the two chocolates you buy. Return _the amount of money you will have leftover after buying the two chocolates_. If there is no way for you to buy two chocolates without ending up in debt, return `money`. Note that the leftover must be non-negative. **Example 1:** ``` **Input:** prices = [1,2,2], money = 3 **Output:** 0 **Explanation:** Purchase the chocolates priced at 1 and 2 units respectively. You will have 3 - 3 = 0 units of money afterwards. Thus, we return 0. ``` **Example 2:** ``` **Input:** prices = [3,2,3], money = 3 **Output:** 3 **Explanation:** You cannot buy 2 chocolates without going in debt, so we return 3. ``` **Constraints:** `2 <= prices.length <= 50` `1 <= prices[i] <= 100` `1 <= money <= 100`",
  "test_case": [
    {
      "label": "Example 1",
      "input": "prices = [1,2,2], money = 3",
      "output": "0 "
    },
    {
      "label": "Example 2",
      "input": "prices = [3,2,3], money = 3",
      "output": "3 "
    }
  ],
  "constraints": [
    "2 <= prices.length <= 50",
    "1 <= prices[i] <= 100",
    "1 <= money <= 100"
  ],
  "python_template": "class Solution(object):\n    def buyChoco(self, prices, money):\n        \"\"\"\n        :type prices: List[int]\n        :type money: int\n        :rtype: int\n        \"\"\"\n        ",
  "java_template": "class Solution {\n    public int buyChoco(int[] prices, int money) {\n        \n    }\n}",
  "metadata": {
    "func_name": "buyChoco"
  }
}