Problem statement

https://binarysearch.com/problems/Run-Length-Encoding/

Solution

Here we can use gropuby.

Complexity

It is O(n) for time and space.

Code

class Solution:
    def solve(self, s):
        return "".join([(str(len(list(j))) + i) for i, j in groupby(s)])