Skip to main content

Command Palette

Search for a command to run...

Popular Interview Questions - Maximum Subarray Sum

Published
•1 min read•View as Markdown
Popular Interview Questions - Maximum Subarray Sum
N
This is Nirbhay Singh currently working as a Software Engineer 1 at Hashedin by Deloitte. I have majorly worked in Springboot and Django but I also have little bit of hands on in React and slowly transitioning to Full stack developer by leveraging AI. My goal right now is to learn and gain more experience in this industry and work on amazing projects

Maximum Subarray Sum

https://www.codingninjas.com/studio/problems/maximum-subarray-sum_630526

Hint :

Code:

long long maxSubarraySum(vector<int> arr, int n)
{
    // Write your code here.
    long long sum = 0;
    long long maxi = 0;
    for(int i=0;i<n;i++){
        sum+=arr[i];

        if(sum<0){
            sum = 0;
        }
        else{
            maxi = max(maxi,sum);
        }
    }

    return maxi;

}

DSA prep

Part 2 of 22

This series is specifically to document and share my learning of Data Structure and Algorithms and building the programmers intuition to solve a problem through coding and getting my first job as SDE.

Up next

Next Greater Element - Popular DSA Questions

Next Greater Element Problem Link: https://www.codingninjas.com/studio/problems/next-greater-element_670312 Hint Video: https://www.loom.com/share/eebada05a6aa43e1b50d66edd24e45c4?sid=63bdad30-8225-4792-9815-9cdf66dd8476 Code: #include<stack> vecto...

More from this blog