def merge(left, right):
    """
    Merges two arrays in non-decreasing order.

    @type   left: array
    @param  left: one of the arrays to merge
    @type  right: array
    @param right: the other array to merge

    @rtype: array
    @return: the merged array
    """

    # Initialize merged array
    merged = []

    # Indices to keep track of position in left and right
    i, j = 0, 0

    # Loop until reached end of left or right
    while i < len(left) and j < len(right):
        # Add smaller element to merged (left element if equal)
        if left[i] <= right[j]:
            merged.append(left[i])
            # Move on to next element in left
            i += 1
        else:
            merged.append(right[j])
            # Move on to next element in right
            j += 1

    # Add leftover elements from either left or right to merged
    if left:
        merged.extend(left[i:])
    if right:
        merged.extend(right[j:])

    return merged