def levenshtein(a, b):
    """Compute the Levenshtein distance between two strings a and b.

    Args:
        a (str): 1st string
        b (str): 2nd string

    Returns:
        int: the levenshtein distance between a and b
    
    Note:
        See https://en.wikipedia.org/wiki/Levenshtein_distance#Iterative_with_two_matrix_rows
    """
    if len(a) < len(b):
        a, b = b, a
    if not b:
        return len(a)
    
    m, n = len(a), len(b)
    previous = list(range(n+1))
    current = [0] * (n+1)
    for i in range(m):
        current[0] = i + 1
        for j in range(n):
            substitution_cost = int(a[i] != b[j]) + previous[j]
            current[j + 1] = min(previous[j + 1] + 1, current[j] + 1, substitution_cost)
        current, previous = previous, current
    return previous[-1]