All problems
Rope Split
Problem
Split a rope at a character index.
chunks is the ordered list of string chunks and k is the split position. Chunks entirely before the split go left, chunks after it go right, and the chunk containing the split is cut into two non-empty pieces. Zero-length pieces are never emitted.
Return [left_chunks, right_chunks].
Hint
A split strictly inside a chunk creates a piece on each side.
Test cases
case 1
in: [["ab","cde","f"],3]
expected: [["ab","c"],["de","f"]]
case 2
in: [["abc"],0]
expected: [[],["abc"]]
case 3
in: [["abc"],3]
expected: [["abc"],[]]
case 4
in: [["ab","cd"],4]
expected: [["ab","cd"],[]]
case 5
in: [["a","b"],1]
expected: [["a"],["b"]]
Starter codePython
def rope_split(chunks, k):
# Your code here
pass5 test cases · run your code against them in the editor