The Captain's Room

  • [deleted]Challenge Author
    + 1 comment

    In Python 3, str is unicode strings. They take more space than byte strings. This may be one of the reasons for getting Runtime Error.

    Code Python 2

    >>> import sys
    >>> print(sum([sys.getsizeof(i) for i in '12345689'*10**5]))
    17600000  
    

    Code Python 3

    >>> import sys
    >>> print(sum([sys.getsizeof(i) for i in '12345689'*10**5]))
    20800000
    

    To overcome this, we can simply avoid creating a huge list, which is causing memory error.

    I have added a solution in Python 3 in Editorial.

    *One can also, try solving this using Counters.