Codility: TieRopes Solution
Lesson 16 Greedy AlgorithmsApproach
Accumulated sum, reset when exceed K
Implementation
1function solution(K, A) {2 let sum = 03 let res = 04 for (const a of A) {5 sum += a6 if (sum >= K) {7 res++8 sum = 09 }10 }11 return res12}
Comments
Loading comments...
Tags
codility
greedy
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: MaxNonoverlappingSegments
Lesson 16 Greedy Algorithms