DEV Community

duccanhole
duccanhole

Posted on

4 1

code every day with me

--DAY 9--

Hi, I am going to make #100DaysOfCode Challenge. Everyday I will try solve 1 problem from leetcode or hackerrank. Hope you can go with me until end.
Now let's solve problem today:
-Problem: Maximum Subarray
-Detail: https://leetcode.com/problems/maximum-subarray/
-My solution (javascript):

var maxSubArray = function(a) {
  let max=a[0],maxE=0;
  for(let i in a){
    maxE+=a[i];
    if(maxE>max) max=maxE;
    if(maxE<0) maxE=0;
  }
  return max;
};
Enter fullscreen mode Exit fullscreen mode

-->If you have better solution or any question, please comment below. I will appreciate.

Top comments (0)

SurveyJS custom survey software

JavaScript UI Libraries for Surveys and Forms

SurveyJS lets you build a JSON-based form management system that integrates with any backend, giving you full control over your data and no user limits. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay