Skip to content
Programming101
Programming101

Learn everything about programming

  • Home
  • CS Subjects
    • IoT – Internet of Things
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programming101
Programming101

Learn everything about programming

HackerEarth Cricket Rating problem solution

YASH PAL, 31 July 2024
In this HackerEarth 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

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;
}
coding problems

Post navigation

Previous post
Next post
  • HackerRank Separate the Numbers solution
  • How AI Is Revolutionizing Personalized Learning in Schools
  • GTA 5 is the Game of the Year for 2024 and 2025
  • Hackerrank Day 5 loops 30 days of code solution
  • Hackerrank Day 6 Lets Review 30 days of code solution
©2025 Programming101 | WordPress Theme by SuperbThemes