Codility: TapeEquilibrium Solution

Lesson 3 Complexity
1function solution(A) {
2 const sum = A.reduce((acc, el) => acc + el, 0)
3 let accSum = 0
4 let diff = []
5 for (const el of A) {
6 accSum += el
7 diff.push(Math.abs(sum - 2 * accSum))
8 }
9 diff.pop()
10 return Math.min.apply(null, diff)
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: PermMissingElem

Lesson 3 Complexity

HoningJS

Search Posts