from typing import Union
from typing import Any


def lastindexof(x: Union[str, list], value: Any) -> int:
    """
    For string input, returns the last index of substring in the input string.
    For array input, returns the last index of value in the input array.
    """
    if isinstance(x, str):
        return x.rfind(str(value))
    else:
        x = list(x)
        try:
            return len(x) - 1 - x[::-1].index(value)
        except ValueError:
            return -1