Problem statement

https://binarysearch.com/problems/Look-and-Say/

Solution

Equal to Leetcode 0038. Count and Say

Complexity

Potentially sequence can extend upto O(2^n) elements, so we have O(2^n) time and space complexity.

Code

class Solution:
    def solve(self, n):
        state = "1"
        for _ in range(n-1):
            state = "".join([str(len(list(j))) + str(i) for i, j in groupby(state)])
        return state