from typing import Union


def array_equal(left_buffer: Union[bytes, bytearray], left_offset: int, left_size: int,
                right_buffer: Union[bytes, bytearray], right_offset: int, right_size: int) -> bool:
    """ Check whether buffers equal with range [offset, offset + size) """
    if left_size != right_size:
        return False
    if left_buffer is right_buffer:
        # same buffer
        if left_offset == right_offset and left_size == right_size:
            # same range
            return True
    pos1 = left_offset + left_size - 1
    pos2 = right_offset + right_size - 1
    while pos2 >= right_offset:
        if left_buffer[pos1] != right_buffer[pos2]:
            # not matched
            return False
        pos1 -= 1
        pos2 -= 1
    # all items matched
    return True