Codility ‘TieRopes’ Solution

Short Problem Definition:

Tie adjacent ropes to achieve the maximum number of ropes of length >= K.

Link

TieRopes

Complexity:

expected worst-case time complexity is O(N);

expected worst-case space complexity is O(N)

Execution:

I am a bit skeptical about the correctness of my solution. It gets 100/100 through…

Solution:
def solution(K, A):
    cnt = 0
    current = 0
    for part in A:
        current += part
        if current >= K:
            cnt +=1
            current = 0

    return cnt

If you enjoyed this post, then make sure you subscribe to my Newsletter and/or Feed.

Facebooktwittergoogle_plusredditpinterestlinkedin