Skip to content

Commit 2bb7a3d

Browse files
committed
small changes and refining project structure
1 parent b71bcaf commit 2bb7a3d

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

solutions/max-contiguous-subarray-general-Solution.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,17 @@ B> So, in the above test case, when i hits 3 where the element is 4 - currentMax
3131
3232
C> But, we have to make sure, that as soon as the current index no is a negative one, and so ( currentMax + arr[i] < currentMax ) - that DOES NOT mean the current run of the sub-array is done upto the previous index. BECAUSE THE NEXT POSITIVE NO MAY BE VERY LARGE
3333
34-
C> the globalMax is just a comparison variable, to keep track of the largest value of currentMax till now.
34+
D) If instead I wrote the currentMax = Math.max(currentMax+arr[i], arr[i]) as below
35+
36+
currentMax = Math.max(currentMax, currentMax + array[i])
37+
38+
Then, the return value will just be the sum of all positive values in the array, not the max sum of a contiguous subarray.
39+
40+
E> the globalMax is just a comparison variable, to keep track of the largest value of currentMax till now.
41+
42+
43+
3544
*/
3645

3746
// For returnning the sub-array instead of the sum, and accetping only non-negative elements in the final contiguous sub-array, see my solutioin below
38-
// /home/paul/codes-Lap/js/challenges/Javascript-Interview_Challenges/InterviewBit/max-contiguous-subarray.js
47+
// /home/paul/codes-Lap/js/challenges/Javascript-Interview_Challenges/InterviewBit/max-contiguous-subarray.js

0 commit comments

Comments
 (0)