Skip to content

Commit

Permalink
Merge pull request #99 from horrible-hacker/main
Browse files Browse the repository at this point in the history
Added solution of POTD 25th of May in C++
  • Loading branch information
Ayu-hack authored Oct 11, 2024
2 parents 580510f + 7c7be2c commit d1af373
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions May 2024/You and Your Books(25 May).cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
class Solution {
public:
long long max_Books(int arr[], int n, int k) {
// Your code here
int front = -1;
int back = -1;
long long max_sum = 0;
long long sum = 0;
for(int i=0;i<n;i++)
{
if(arr[i]<=k)
{
if(front<0)
{
front = i;
back = i;
sum = sum + arr[i];
}
else
{
sum = sum + arr[i];
back++;
}
}
else
{
sum = 0;
front = -1;
back = -1;
}
if(max_sum<sum)
{
max_sum = sum;
}
}
return max_sum;
}
};

0 comments on commit d1af373

Please sign in to comment.