""" From https://twitter.com/Al_Grigor/status/1357028887209902088 Most candidates cannot solve this interview problem: * Input: "aaaabbbcca" * Output: [("a", 4), ("b", 3), ("c", 2), ("a", 1)] Write a function that converts the input to the output I ask it in the screening interview and give it 25 minutes How would you solve it? """ def rle(x): res = [[x[0],1]] for i in range(1,len(x)): if x[i] == x[i-1]: res[-1][1]+=1 else: res.append([x[i],1]) return [tuple(j) for j in res] if __name__=="__main__": print(rle("aaaabbbcca"))