Codility 'TieRopes' Solution

Martin Kysel · August 25, 2014

Short Problem Definition:

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

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

Twitter, Facebook

To learn more about solving Coding Challenges in Python, I recommend these courses: Educative.io Python Algorithms, Educative.io Python Coding Interview.