# HackerEarth Cricket Rating problem solution

In this Leetcode Cricket Rating problem solution, India is a cricket-crazy nation. Chang also loves cricket and computations related to cricket. Chang has created a Cricket app. This app analyses the performance of a cricketer. If a cricketer under-performs, then a negative rating is awarded. If performance is good, then a positive rating is awarded to the cricketer. Chang wants to analyze the performance of a cricketer over a period of N matches. Chang wants to find the consistency of a cricketer. So he wants to find out the maximum consistent sum of cricket rating of a batsman or a bowler only if his overall rating is positive over that period. Help change in doing so.

## HackerEarth Cricket Rating problem solution.

`#include <iostream>#include <cstdio>#include <algorithm>using namespace std; int prefunction(int a[],int length){    int max1 = 0,max2 = 0;    for(int i = 0;i<length;i++){        max2 = max2 + a[i];        if(max2 < 0)            max2 = 0;        if(max1 < max2)            max1 = max2;    }    return max1;}int main(){    int n;    cin >> n;    int a[n+1];    for(int i = 0;i<n;i++)        cin >> a[i];    int result = prefunction(a,n);    cout << result << endl;    return 0;}`