> 
> kadane's algorithm implementation 
>  input = (t=1;n=3;arr={-1,4,5}) gives output 8 but expected output was 9.
> 
> 
> 

```
#include <iostream>
#include<cmath>

using namespace std;

int Max( int *arr, int n){
  int currmax = arr[0];
  int globalmax = arr[0];
  for(int i = 1; i < n; i++) {
    currmax= max(currmax, currmax + arr[i]);
    if(currmax > globalmax)
      globalmax = currmax;
  }
  return globalmax;
}

int main() {
  int t;
  cin >> t;
  while(t--){
    int n;
    cin >> n;
    int arr[n];
    for(int i = 0; i < n; i++) cin >> arr[i];
      cout << Max(arr, n) << " ";
  }
}

```