We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
js solution, use Kadane's algorithm for the subarray sum, however seems failing the one long test
functionmaxSubarray(arr){letmaxSeq=pstvSum(arr)letmin=Math.min(...arr)letmax=Math.max(...arr)if(min>=0){return[maxSeq,maxSeq]}elseif(max<=0){return[max,max]}else{// Kadane's algorithm for subArray max sumreturn[maxSubArr(arr),maxSeq]}}functionpstvSum(a){if(a.length==0)return0returna.reduce((tot,curr)=>{if(curr>0)tot+=currreturntot})}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
The Maximum Subarray
You are viewing a single comment's thread. Return to all comments →
js solution, use Kadane's algorithm for the subarray sum, however seems failing the one long test