Codility: MaxSliceSum Solution
Lesson 9 Maximum Slice ProblemApproach
Kadane algorithm (maximum subarray)
Implementation
1function solution(A) {2 let max = A[0]3 let acc = 04 for (let i = 0; i < A.length; i++) {5 acc += A[i]6 max = Math.max(max, acc)7 acc = acc < 0 ? 0 : acc8 }910 return max11}
Comments
Loading comments...
Tags
codility
Apply and earn a $2,500 bonus once you're hired on your first job!
Clients from the Fortune 500 to Silicon Valley startups
Choose your own rate, get paid on time
From hourly, part-time, to full-time positions
Flexible remote working environment
A lot of open JavaScript jobs!!
Fact corner: Referred talent are 5x more likely to pass the Toptal screening process than the average applicant.
Still hesitate? Read HoningJS author's guide on dealing with Toptal interview process.
Next Post
Codility: MaxProfit
Lesson 9 Maximum Slice Problem
Previous Post
Codility: MaximumDoubleSliceSum
Lesson 9 Maximum Slice Problem