Gotta learn algorithms!
Initialize:
max_so_far = 0
max_ending_here = 0
Loop for each element of the array
(a) max_ending_here = max_ending_here + a[i]
(b) if(max_ending_here < 0)
max_ending_here = 0
(c) if(max_so_far < max_ending_here)
max_so_far = max_ending_here
return max_so_far
Sum Formula
1. Get the sum of numbers: total = n*(n+1)/2
2. Subtract all the numbers from sum and you will get the missing number.
XOR
1) XOR all the array elements, let the result of XOR be X1.
2) XOR all numbers from 1 to n, let XOR be X2.
3) XOR of X1 and X2 gives the missing number.
curr_sum = arr[0]
start = 0
for (i = 1; i <= n; i++)
while (curr_sum > sum && start < i - 1)
curr_sum -= arr[start] # if bigger than sum, subtract the beginning #s
start++
if (curr_sum == n)
return [start, i - 1] # i-1 bc last elem
if (i < n)
curr_sum += arr[i]