SarthakKeshari / Java-Questions-and-Solutions

This repository aims to solve and create new problems from different spheres of coding. A path to help students to get access to solutions and discuss their doubts.
MIT License
47 stars 98 forks source link

Added Solution for MaximumSubarray.java #331

Closed sagar-monga closed 3 years ago

sagar-monga commented 3 years ago

Issue Id you have worked upon -

245

Briefly explain your program logic -

I have used Kadane's Algorithm to solve the problem. We keep track of the largest subsequence till the current element and if upon adding the current element, we find that the sum exceeds the maximum sum, we add the current element to the longest subsequence. Otherwise, drop the previous sum, and replace it with the current element instead.

Screenshots(Attach 2 screenshots of your own input and output) -

Input Input

Output Output


Checklist:

Eg - If your code follow the below guidelines. Kindly change [] to [x]

All the conditions should be fulfilled for considering your code for merging -