def _partition(nums, left, right):
    """Util method for quicksort_ip() to rearrange nums in place."""
    # Use right number as pivot.
    right_num = nums[right]

    # Rearrange numbers w.r.t. pivot: 
    # - For left <= k <= i: nums[k] <= pivot,
    # - For i+1 <= k <= j-1: nums[k] > pivot,
    # - For k = right: nums[k] = pivot.
    i = left - 1
    for j in range(left, right):
        if nums[j] <= right_num:
            i += 1
            nums[i], nums[j] = nums[j], nums[i]

    # Swap num[i+1] and pivot, to rearrange to correct order.
    nums[i + 1], nums[right] = nums[right], nums[i + 1]
    return i + 1