From 750dbb1680622c65b9d15e68273097ff43e12749 Mon Sep 17 00:00:00 2001 From: ashutosh-das-id Date: Wed, 12 Aug 2026 21:49:51 -0700 Subject: [PATCH] Implement Mock-10: Buy and Sell Stock 2 --- BuySellStock2.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 BuySellStock2.java diff --git a/BuySellStock2.java b/BuySellStock2.java new file mode 100644 index 0000000..56ff8da --- /dev/null +++ b/BuySellStock2.java @@ -0,0 +1,16 @@ +/** + * Time Complexity: O(n) where n is the length of prices + * Space Complexity: O(1) + */ +class Solution { + public int maxProfit(int[] prices) { + int result = 0; + for(int i=0; i prices[i]){ + result += prices[i+1] - prices[i]; + } + } + return result; + + } +} \ No newline at end of file