-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #99 from horrible-hacker/main
Added solution of POTD 25th of May in C++
- Loading branch information
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
}; |