All problems
CTC Collapse
Problem
Collapse a CTC path: remove consecutive repeats, then drop every token equal to blank_index.
A blank between two identical tokens keeps both after collapsing, and an empty path stays empty.
Hint
Do the repeat collapse first, then remove blanks.
Test cases
case 1
in: [[1,1,2,2,2,0,3],0]
expected: [1,2,3]
case 2
in: [[0,0,0],0]
expected: []
case 3
in: [[],0]
expected: []
case 4
in: [[1,0,1],0]
expected: [1,1]
case 5
in: [[1,1,1,1],5]
expected: [1]
Starter codePython
def ctc_collapse(path, blank_index=0):
# Your code here
pass5 test cases · run your code against them in the editor