'''
#### Name:  Dutch National Flag
Link: [link]()

#### Sub_question_name: Three way partitioning of an array around a given value 
Link: [link]()

'''


def parition(nums, range):
    n = len(nums)

    low = range[0]
    high = range[1]

    start = 0
    end = n-1
    i = 0
    while i <= end:
        if nums[i] < low:  # swap with starts
            nums[start], nums[i] = nums[i], nums[start]
            i += 1
            start += 1

        elif nums[i] > high:
            nums[end], nums[i] = nums[i], nums[end]   # We donot increment i here as we many have to check for it
            end -= 1

        else:
            i += 1

    print(nums)


arr = [1, 14, 5, 20, 4, 2, 54,  20, 87, 98, 3, 1, 32]
range = (10, 20)
parition(arr, range)

7f7e892e6ca3142d72551f23fa6a7c58ae1c4b14
<mask token>

<mask token>


def parition(nums, range):
    n = len(nums)
    low = range[0]
    high = range[1]
    start = 0
    end = n - 1
    i = 0
    while i <= end:
        if nums[i] < low:
            nums[start], nums[i] = nums[i], nums[start]
            i += 1
            start += 1
        elif nums[i] > high:
            nums[end], nums[i] = nums[i], nums[end]
            end -= 1
        else:
            i += 1
    print(nums)


<mask token>

<mask token>


def parition(nums, range):
    n = len(nums)
    low = range[0]
    high = range[1]
    start = 0
    end = n - 1
    i = 0
    while i <= end:
        if nums[i] < low:
            nums[start], nums[i] = nums[i], nums[start]
            i += 1
            start += 1
        elif nums[i] > high:
            nums[end], nums[i] = nums[i], nums[end]
            end -= 1
        else:
            i += 1
    print(nums)


<mask token>
parition(arr, range)

<mask token>


def parition(nums, range):
    n = len(nums)
    low = range[0]
    high = range[1]
    start = 0
    end = n - 1
    i = 0
    while i <= end:
        if nums[i] < low:
            nums[start], nums[i] = nums[i], nums[start]
            i += 1
            start += 1
        elif nums[i] > high:
            nums[end], nums[i] = nums[i], nums[end]
            end -= 1
        else:
            i += 1
    print(nums)


arr = [1, 14, 5, 20, 4, 2, 54, 20, 87, 98, 3, 1, 32]
range = 10, 20
parition(arr, range)

'''
#### Name:  Dutch National Flag
Link: [link]()

#### Sub_question_name: Three way partitioning of an array around a given value 
Link: [link]()

'''


def parition(nums, range):
    n = len(nums)

    low = range[0]
    high = range[1]

    start = 0
    end = n-1
    i = 0
    while i <= end:
        if nums[i] < low:  # swap with starts
            nums[start], nums[i] = nums[i], nums[start]
            i += 1
            start += 1

        elif nums[i] > high:
            nums[end], nums[i] = nums[i], nums[end]   # We donot increment i here as we many have to check for it
            end -= 1

        else:
            i += 1

    print(nums)


arr = [1, 14, 5, 20, 4, 2, 54,  20, 87, 98, 3, 1, 32]
range = (10, 20)
parition(arr, range)
