def sumblock(sequence, right_index, total):
    """
    Finds the contigous block whose sum adds up to total, starting at index i
    and works backward (to the left)

    >>> sumblock([1, 2, 3, 4, 5], right_index=4, total=5)
    [4]

    >>> sumblock([1, 2, 3, 4, 5], right_index=3, total=7)
    [2, 3]

    >>> sumblock([1, 2, 3, 4, 5], right_index=3, total=9)
    [1, 2, 3]
    """
    if sequence[right_index] == total:
        return [right_index]

    sub_total = sequence[right_index]
    for left_index in range(right_index - 1, -1, -1):
        sub_total += sequence[left_index]
        if sub_total == total:
            return list(range(left_index, right_index + 1))
        elif sub_total > total:
            return sumblock(sequence, right_index - 1, total)

    return []