Alibaba Group interview question

String problem in LeetCode. Some basic list operation in Python should suffice.