Last active
June 11, 2020 11:45
-
-
Save leonidkuznetsov18/2426da0975016bb2ecf536471b33ff29 to your computer and use it in GitHub Desktop.
maximum sub arrays
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function maxSubArray(nums) { | |
| let currSum = -Infinity; | |
| let maxSum = -Infinity; | |
| for (let i = 0; i < nums.length; i++) { | |
| currSum = Math.max(0, currSum); | |
| currSum +=nums[i]; | |
| maxSum = Math.max(maxSum, currSum); | |
| } | |
| return maxSum; | |
| }; | |
| // Big O Analysis: | |
| // Time: O(n) | |
| // A simple linear scan through an array. | |
| // Space: O(1) | |
| // No memory does not scale based on input. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment