Skip to content

Latest commit

 

History

History
17 lines (9 loc) · 1.12 KB

File metadata and controls

17 lines (9 loc) · 1.12 KB

Time Complexity (Big O Time):

  1. The program uses a single loop to iterate through the elements of the nums array. Let's assume there are 'n' elements in the array.

  2. In each iteration of the loop, the program performs constant time operations such as addition, comparison, and calls to Math.max.

  3. Therefore, the time complexity of the program is O(n), where 'n' is the number of elements in the input array nums.

Space Complexity (Big O Space):

  1. The space complexity of the program is O(1), which means it uses a constant amount of additional space regardless of the size of the input array.

  2. The program uses a few integer variables (maxi and sum) to keep track of the maximum subarray sum and the current subarray sum, respectively. These variables require constant space.

  3. The space complexity does not depend on the size of the input array nums.

In summary, the time complexity of the provided program is O(n), and the space complexity is O(1), where 'n' is the number of elements in the input array nums. The program efficiently finds the maximum subarray sum using a single pass through the array.