From 60ada73fb40fb305ea099e6d8d0c79f154c7e64f Mon Sep 17 00:00:00 2001 From: chayan das <110921638+Chayandas07@users.noreply.github.com> Date: Thu, 21 Dec 2023 00:07:25 +0530 Subject: [PATCH] Create 2706. Buy Two Chocolates --- 2706. Buy Two Chocolates | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 2706. Buy Two Chocolates diff --git a/2706. Buy Two Chocolates b/2706. Buy Two Chocolates new file mode 100644 index 0000000..908bed9 --- /dev/null +++ b/2706. Buy Two Chocolates @@ -0,0 +1,19 @@ +class Solution { +public: + int buyChoco(vector& prices, int money) { + auto it = min_element(prices.begin(),prices.end()); + int index = it - prices.begin(); + int mini1 = prices[index]; + // cout << mini1 << endl; + prices.erase(prices.begin()+index); + it = min_element(prices.begin(),prices.end()); + index = it - prices.begin(); + int mini2 = prices[index]; + // cout << mini2 << endl; + + int sum = mini1 + mini2; + // cout << sum << endl; + if(sum <= money) return money - sum; + return money; + } +};