human
Maximum ranges that can be uniquely represented by any integer from the range | Function to find the maximum number of ranges where each range can be uniquely represented by an integer.
Sort the ranges in ascending order.
Stores the count of ranges.
Stores previously assigned range.
Traverse the vector arr [ ].
Skip the similar ranges of size 1.
Find the range of integer available to be assigned.
Check if an integer is available to be assigned.
Update the previously assigned range.
Update the count of range.
Return the maximum count of ranges.
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to maximum ranges that can be uniquely represented by any integer from the range and the other steps required.
 def maxRanges ( arr , N ) :
	arr . sort ( )
	count = 1
	prev = arr [ 0 ]
	for i in range ( 1 , N ) :
		last = arr [ i - 1 ]
		current = arr [ i ]
		if ( last [ 0 ] == current [ 0 ] and last [ 1 ] == current [ 1 ] and current [ 1 ] == current [ 0 ] ) :
			continue
		start = max ( prev [ 0 ] , current [ 0 ] - 1 )
		end = max ( prev [ 1 ] , current [ 1 ] )
		if ( end - start > 0 ) :
			prev [ 0 ] = 1 + start
			prev [ 1 ] = end
			count += 1
	return count
if __name__ == " _ _ main _ _ " :
	arr = [ [ 1 , 4 ] , [ 4 , 4 ] , [ 2 , 2 ] , [ 3 , 4 ] , [ 1 , 1 ] ]
	N = len ( arr )
	print ( maxRanges ( arr , N ) )