def partition(array, start, end): 
    """
    This function takes last element as pivot, places the pivot element at its 
    correct position in the array.
    All smaller elements smaller than the pivot are placed to the left of pivot 
    and all greater elements to right 
    """
    i = (start - 1)
    pivot = array[end]

    for j in range(start, end): 

        # If current element is smaller than or equal to pivot 
        if array[j] <= pivot: 
        
            # increment index of smaller element 
            i = i + 1
            array[i], array[j] = array[j], array[i]

    array[i + 1], array[end] = array[end], array[i + 1] 
    return (i + 1)