Codility: MaxSliceSum Solution

Lesson 9 Maximum Slice Problem

Approach

Kadane algorithm (maximum subarray)

Implementation

1function solution(A) {
2 let max = A[0]
3 let acc = 0
4 for (let i = 0; i < A.length; i++) {
5 acc += A[i]
6 max = Math.max(max, acc)
7 acc = acc < 0 ? 0 : acc
8 }
9
10 return max
11}

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

Jan 25, 2021

Lesson 9 Maximum Slice Problem

Previous Post

Codility: MaximumDoubleSliceSum

Jan 25, 2021

Lesson 9 Maximum Slice Problem

HoningJS

Search Posts