def kth_largest_element(nums, left, right, k):
    """
    Find kth largest element in given array (like quick sort)

    :param nums: given array
    :type nums: list[int]
    :param left: left position to begin
    :type left: int
    :param right: right position to end
    :type right: int
    :param k: kth
    :type k: int
    :return: kth-largest element
    :rtype: int
    """
    pivot = nums[right]
    i = left - 1
    for j in range(left, right):
        if nums[j] <= pivot:
            i += 1
            nums[i], nums[j] = nums[j], nums[i]
    nums[i + 1], nums[right] = nums[right], nums[i + 1]

    if i + 1 == k:
        return nums[i + 1]
    elif i + 1 > k:
        return kth_largest_element(nums, left, i, k)
    else:
        return kth_largest_element(nums, i + 2, right, k)