Minimum Number of Bullets required to penetrate all bricks | Function to find the minimum number of bullets required to penetrate all bricks ; Sort the points in ascending order ; Check if there are no points ; Iterate through all the points ; Increase the count ; Return the count ; Driver Code ; Given coordinates of bricks ; Function call
def findMinBulletShots ( points ) : NEW_LINE INDENT for i in range ( len ( points ) ) : NEW_LINE INDENT points [ i ] = points [ i ] [ : : - 1 ] NEW_LINE DEDENT points = sorted ( points ) NEW_LINE for i in range ( len ( points ) ) : NEW_LINE INDENT points [ i ] = points [ i ] [ : : - 1 ] NEW_LINE DEDENT if ( len ( points ) == 0 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT cnt = 1 NEW_LINE curr = points [ 0 ] [ 1 ] NEW_LINE for j in range ( 1 , len ( points ) ) : NEW_LINE INDENT if ( curr < points [ j ] [ 0 ] ) : NEW_LINE INDENT cnt += 1 NEW_LINE curr = points [ j ] [ 1 ] NEW_LINE DEDENT DEDENT return cnt NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT bricks = [ [ 5000 , 900000 ] , [ 1 , 100 ] , [ 150 , 499 ] ] NEW_LINE print ( findMinBulletShots ( bricks ) ) NEW_LINE DEDENT