From 63e7b31184e6c3b9ba7ccf9bfd6870d4389cf6b9 Mon Sep 17 00:00:00 2001 From: "M.V. Hutz" Date: Fri, 23 Jan 2026 23:11:32 -0500 Subject: [PATCH] feat:s oivjsovji --- pkg/best_time_to_buy_and_sell_stock/main.go | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 pkg/best_time_to_buy_and_sell_stock/main.go diff --git a/pkg/best_time_to_buy_and_sell_stock/main.go b/pkg/best_time_to_buy_and_sell_stock/main.go new file mode 100644 index 0000000..a9003c7 --- /dev/null +++ b/pkg/best_time_to_buy_and_sell_stock/main.go @@ -0,0 +1,11 @@ +package besttimetobuyandsellstock + +func MaxProfit(prices []int) int { + buy, sell := 1_000_000_000, 0 + + for _, price := range prices { + buy, sell = min(buy, price), max(sell, price-buy) + } + + return sell +}