Skip to content

Added CP handbook #439

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions C++/Maximum_Subarray_Sum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@
#include <vector>

using namespace std;
int maxSubarraySum(vector<int> nums, int n){
int best = 0, sum = 0;
for(int i = 0; i < n; i++) {
sum = max(nums[i], sum + nums[i]);
best = max(best, sum);
}
return best;

}
int main() {
int n;
cin >> n;
Expand All @@ -12,13 +20,8 @@ int main() {
for(int i = 0; i < n; i++)
cin >> nums[i];

int best = 0, sum = 0;
for(int i = 0; i < n; i++) {
sum = max(nums[i], sum + nums[i]);
best = max(best, sum);
}

int best =maxSubarraySum(nums,n);
cout << best << endl;

return 0;
}
}
1 change: 1 addition & 0 deletions C++/Program to reverse number.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <iostream>
using namespace std;
//reverse function
int reverseNum(int n){
int reverse=0,rem;
while(n!=0)
Expand Down
Binary file added Useful-Books/C++/CP handbook.pdf
Binary file not shown.