human
What is a code to count of available non and the other steps required given the following:
Count of available non | Function to find the pivot index.
Function to implement Quick Sort.
Pivot is pointing to pivot index before which every element is smaller and after pivot , every element is greater.
Sort the array before pivot element.
Sort the array after pivot element.
Function to count the available intervals from the given range of numbers.
If range starts after 0 then an interval is available from 0 to start [ 0 ].
When a new interval starts.
Since index variable i is being incremented , the current active interval will also get incremented.
When the current interval ends.
Since index variable j is being decremented , the currect active interval will also get decremented.
When start and end both are same there is no change in currActive.
If the end of interval is before the range so interval is available at the end.
Driver code.
Sort the start array.
Sort the end array.
Calling the function"
How can the above be solved in Python?
assistant
#Here is code to count of available non and the other steps required.
 def partition ( arr , l , h ) :
	pivot = arr [ l ]
	i = l + 1
	j = h
	while ( i <= j ) :
		while ( i <= h and arr [ i ] < pivot ) :
			i += 1
		while ( j > l and arr [ j ] > pivot ) :
			j -= 1
		if ( i < j ) :
			temp = arr [ i ]
			arr [ i ] = arr [ j ]
			arr [ j ] = temp
			i += 1
			j -= 1
		else :
			i += 1
	arr [ l ] = arr [ j ]
	arr [ j ] = pivot
	return j
def sortArray ( arr , l , h ) :
	if ( l >= h ) :
		return
	pivot = partition ( arr , l , h )
	sortArray ( arr , l , pivot - 1 )
	sortArray ( arr , pivot + 1 , h )
def findMaxIntervals ( start , end , n , R ) :
	ans = 0
	prev = 0
	currActive = 0
	i = 0
	j = 0
	if ( start [ 0 ] > 0 ) :
		ans += 1
	while ( i < n and j < n ) :
		if ( start [ i ] < end [ j ] ) :
			i += 1
			currActive += 1
		elif ( start [ i ] > end [ j ] ) :
			j += 1
			currActive -= 1
		else :
			i += 1
			j += 1
		if ( currActive == 0 ) :
			ans += 1
	if ( end [ n - 1 ] < R ) :
		ans += 1
	return ans
if __name__ == ' _ _ main _ _ ' :
	R = 10
	N = 3
	start = [ 2 , 5 , 8 ]
	end = [ 3 , 9 , 10 ]
	sortArray ( start , 0 , N - 1 )
	sortArray ( end , 0 , N - 1 )
	print ( findMaxIntervals ( start , end , N , R ) )