Skip to content

Merge pull request #1 from yuvrajsingh96633/patch-1#4

Open
yuvrajsingh96633 wants to merge 5 commits into
yuvraj1318:mainfrom
yuvrajsingh96633:main
Open

Merge pull request #1 from yuvrajsingh96633/patch-1#4
yuvrajsingh96633 wants to merge 5 commits into
yuvraj1318:mainfrom
yuvrajsingh96633:main

Conversation

@yuvrajsingh96633

Copy link
Copy Markdown
Contributor

Patch 1
#CPP-Functions #CPP-Basics

class Solution {

public:

int max(int a,int b){
if(a>b)
return a;
else
return b;
}

bool isNeg(int arr[],int n){
    int c=0;
    for(int i=0;i<n;i++){
        if(arr[i]<0)
        c++;
    }
    if(c==n)
    return true;
    else 
    return false;
}

long long maxSubarraySum(int arr[], int n){
    
    // Your code here
    long long sum=0;
    if(isNeg(arr,n)){
        int min=arr[0];
        for(int i=1;i<n;i++){
            if(min<arr[i])
            min=arr[i];
        }
        return min;
    }
    else {
    long long maxi=arr[0];
    for(int i=0;i<n;i++){
        sum=sum+arr[i];
        maxi=max(maxi,sum);
        if(sum<0)
        sum=0;
    }
    return maxi;
    }
}

};

Merge pull request #2 from yuvrajsingh96633/main
Merge pull request #3 from yuvrajsingh96633/patch-1
Merge pull request #4 from yuvrajsingh96633/main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant