def find_all_indexes(text, pattern):
    """Return a list of starting indexes of all occurrences of pattern in text,
    or an empty list if not found."""

    '''
    worksheet: String Algorithms, pt. 2

    let p = len(pattern)
    let t = len(text)

    p * t = checking every letter in text against every letter in pattern
    p(p-1) = p(p^2 - 1) = # REVIEW N/A VALUES IN WORKSHEET

    Best time complexity -- O(___), 
    Worst time complexity -- 
        O( p*t - p^2 + p ) = 
        O( p*t + 1) - p^2 ) =
        O( p*t - p^2 ) remove constant since it doesn't have that much of an effect

    if p < t, then O(p * t)
    '''

    if pattern == '':
        return list(range(0, len(text)))

    index = 0
    t_index = 0  # first letter of pattern
    matching_indexes_list = []
    
    while index <= len(text) - len(pattern):
        if text[index + t_index] == pattern[t_index]:
            # if t_index is the last index in pattern
            if t_index == len(pattern) - 1:
                matching_indexes_list.append(index)
                t_index = 0
                index += 1
            else:
                t_index += 1
        else:
            t_index = 0  # reset
            index += 1
                
    return matching_indexes_list