All problems
Rope Index Query
Problem
Return the character at a given index in a rope.
chunks is the ordered list of strings. Walk the chunks accumulating lengths until the chunk containing the index is found.
Return the character, or None when the index is out of range.
Hint
The offset inside the found chunk is index minus the accumulated length.
Test cases
case 1
in: [["ab","cde"],3]
expected: "d"
case 2
in: [["ab"],2]
expected: null
case 3
in: [[],0]
expected: null
case 4
in: [["a","b","c"],0]
expected: "a"
Starter codePython
def rope_index(chunks, i):
# Your code here
pass4 test cases · run your code against them in the editor