From f0b42ad803722c0a5c134091f4035d019c41d225 Mon Sep 17 00:00:00 2001
From: Samson Okeji <67550977+Psalmzee@users.noreply.github.com>
Date: Tue, 25 Oct 2022 20:13:54 +0100
Subject: [PATCH 1/4] Added Untitled Diagram.drawio
---
SamsonOkeji/Untitled Diagram.drawio | 1 +
1 file changed, 1 insertion(+)
create mode 100644 SamsonOkeji/Untitled Diagram.drawio
diff --git a/SamsonOkeji/Untitled Diagram.drawio b/SamsonOkeji/Untitled Diagram.drawio
new file mode 100644
index 0000000..30212bd
--- /dev/null
+++ b/SamsonOkeji/Untitled Diagram.drawio
@@ -0,0 +1 @@
+UzV2zq1wL0osyPDNT0nNUTV2VTV2LsrPL4GwciucU3NyVI0MMlNUjV1UjYwMgFjVyA2HrCFY1qAgsSg1rwSLBiADYTaQg2Y1AA==
\ No newline at end of file
From 1c13078a401ddf5b7582ea0aec11382fc760741a Mon Sep 17 00:00:00 2001
From: Samson Okeji <67550977+Psalmzee@users.noreply.github.com>
Date: Tue, 25 Oct 2022 20:48:17 +0100
Subject: [PATCH 2/4] Added Untitled Diagram.drawio
---
SamsonOkeji/Untitled Diagram.drawio | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/SamsonOkeji/Untitled Diagram.drawio b/SamsonOkeji/Untitled Diagram.drawio
index 30212bd..c79b089 100644
--- a/SamsonOkeji/Untitled Diagram.drawio
+++ b/SamsonOkeji/Untitled Diagram.drawio
@@ -1 +1 @@
-UzV2zq1wL0osyPDNT0nNUTV2VTV2LsrPL4GwciucU3NyVI0MMlNUjV1UjYwMgFjVyA2HrCFY1qAgsSg1rwSLBiADYTaQg2Y1AA==
\ No newline at end of file
+UzV2zq1wL0osyPDNT0nNUTV2VTV2LsrPL4GwciucU3NyVI0MMlNUjV1UjYwMgFjVyA2HrCFY1qAgsSg1rwSLBiADYTaQg2Y1AA==
\ No newline at end of file
From 02c42b649e29fb804b4ada3b7b84ebb3c1883a53 Mon Sep 17 00:00:00 2001
From: Samson Okeji <67550977+Psalmzee@users.noreply.github.com>
Date: Tue, 25 Oct 2022 22:30:43 +0100
Subject: [PATCH 3/4] Delete Untitled Diagram.drawio
---
SamsonOkeji/Untitled Diagram.drawio | 1 -
1 file changed, 1 deletion(-)
delete mode 100644 SamsonOkeji/Untitled Diagram.drawio
diff --git a/SamsonOkeji/Untitled Diagram.drawio b/SamsonOkeji/Untitled Diagram.drawio
deleted file mode 100644
index c79b089..0000000
--- a/SamsonOkeji/Untitled Diagram.drawio
+++ /dev/null
@@ -1 +0,0 @@
-UzV2zq1wL0osyPDNT0nNUTV2VTV2LsrPL4GwciucU3NyVI0MMlNUjV1UjYwMgFjVyA2HrCFY1qAgsSg1rwSLBiADYTaQg2Y1AA==
\ No newline at end of file
From 6ed3d23af34fd4aaba9271439c7bc0ce9fe5d5e2 Mon Sep 17 00:00:00 2001
From: Samson Okeji
Date: Tue, 25 Oct 2022 22:44:26 +0100
Subject: [PATCH 4/4] Updated MaxProdSubArray
---
SamsonOkeji/Arrays/day-14/MaxProdSubArray | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/SamsonOkeji/Arrays/day-14/MaxProdSubArray b/SamsonOkeji/Arrays/day-14/MaxProdSubArray
index e69de29..05e25ea 100644
--- a/SamsonOkeji/Arrays/day-14/MaxProdSubArray
+++ b/SamsonOkeji/Arrays/day-14/MaxProdSubArray
@@ -0,0 +1,20 @@
+var maxProduct = function(nums) {
+ // Max product in the current contiguous array
+ let currentMax = nums[0];
+ // Min product in the current contiguous array. We need this value in case we encounter 2 negative numbers whose product could potentially give us the max product of the entire array
+ let currentMin = nums[0];
+ // Max product of a contiguous array
+ let finalMax = nums[0];
+
+ for(let i = 1; i < nums.length; i++){
+ let temp = currentMax
+ // Because we are looking for a contiguous subarray product, the current max must contain the current number in the array.
+ currentMax = Math.max(Math.max(currentMax * nums[i], currentMin*nums[i]), nums[i])
+ // Use temp here in case the previous currentMax was negative
+ currentMin = Math.min(Math.min(temp * nums[i], currentMin*nums[i]), nums[i])
+ // Record highest max at the end of every contiguous subarray
+ finalMax = Math.max(currentMax, finalMax);
+ }
+
+ return finalMax;
+};
\ No newline at end of file