Minimum number of integers required such that each Segment contains at least one of them | Function to compute minimum number of points which cover all segments ; Sort the list of tuples by their second element . ; To store the solution ; Iterate over all the segments ; Get the start point of next segment ; Loop over all those segments whose start point is less than the end point of current segment ; Print the possibles values of M ; Driver Code ; Starting points of segments ; Ending points of segments ; Insert ranges in points [ ] ; Function Call
def minPoints ( points ) : NEW_LINE INDENT points . sort ( key = lambda x : x [ 1 ] ) NEW_LINE coordinates = [ ] NEW_LINE i = 0 NEW_LINE while i < n : NEW_LINE INDENT seg = points [ i ] [ 1 ] NEW_LINE coordinates . append ( seg ) NEW_LINE p = i + 1 NEW_LINE if p >= n : NEW_LINE INDENT break NEW_LINE DEDENT arrived = points [ p ] [ 0 ] NEW_LINE while seg >= arrived : NEW_LINE INDENT p += 1 NEW_LINE if p >= n : NEW_LINE INDENT break NEW_LINE DEDENT arrived = points [ p ] [ 0 ] NEW_LINE DEDENT i = p NEW_LINE DEDENT for point in coordinates : NEW_LINE INDENT print ( point , end = " ▁ " ) NEW_LINE DEDENT DEDENT n = 4 NEW_LINE start = [ 4 , 1 , 2 , 5 ] NEW_LINE end = [ 7 , 3 , 5 , 6 ] NEW_LINE points = [ ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT tu = ( start [ i ] , end [ i ] ) NEW_LINE points . append ( tu ) NEW_LINE DEDENT minPoints ( points ) NEW_LINE