From 7d31376408a514c760bb5694138b21184c726246 Mon Sep 17 00:00:00 2001 From: terminaldweller Date: Tue, 19 Dec 2023 20:01:59 -0500 Subject: 2706 --- 2706/main.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 2706/main.py (limited to '2706') diff --git a/2706/main.py b/2706/main.py new file mode 100755 index 0000000..697d312 --- /dev/null +++ b/2706/main.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python +import typing + + +class Solution: + def buyChoco(self, prices: typing.List[int], money: int) -> int: + price_dict: typing.Dict = {} + for i in range(len(prices)): + price_dict[prices[i]] = ( + price_dict[prices[i]] + 1 if prices[i] in price_dict else 1 + ) + + mini = min(prices) + if price_dict[mini] >= 2: + if mini * 2 <= money: + return money - mini * 2 + else: + return money + + slider = mini + 1 + maxi = max(prices) + while slider <= maxi: + if slider in price_dict: + if mini + slider <= money: + return money - mini - slider + slider += 1 + + return money + + +def main(): + solution = Solution() + print(solution.buyChoco([1, 2, 1, 3, 2], 4)) + print(solution.buyChoco([10, 10, 10, 10], 20)) + print(solution.buyChoco([1, 2, 2], 3)) + print(solution.buyChoco([3, 2, 3], 3)) + + +if __name__ == "__main__": + main() -- cgit v1.2.3