def array_to_intervals(array):
    """
    >>> array_to_intervals([2, 1, 1, 1, 3, 3, 4, 4, 1, 1, 2, 2])[1]
    [(1, 4), (8, 10)]
    >>> array_to_intervals([2, 1, 1, 1, 3, 3, 4, 4, 1, 1, 2, 2])[2]
    [(0, 1), (10, 11)]
    >>> array_to_intervals([2, 1, 1, 1, 3, 3, 4, 4, 1, 1, 2, 2])[3]
    [(4, 6)]
    >>> array_to_intervals([2, 1, 1, 1, 3, 3, 4, 4, 1, 1, 2, 2])[4]
    [(6, 8)]
    >>> array_to_intervals([])
    {}
    """

    if len(array) == 0:
        return {}

    interval_dict = {}
    last_val = array[0]
    interval_start = 0
    for index, val in enumerate(array):

        # Assign a list of intervals to this value.
        if val not in interval_dict:
            interval_dict[val] = []

        # Check if we have finished an interval.
        if val != last_val:
            interval_dict[last_val].append((interval_start, index))
            interval_start = index
            last_val = val

    # Assign the last interval.
    if interval_start != len(array) - 1:
        interval_dict[last_val].append((interval_start, len(array) - 1))

    return interval_dict