Minimum Numbers of cells that are connected with the smallest path between 3 given cells | Function to return the minimum cells that are connected via the minimum length path ; Array to store column number of the given cells ; Sort cells in ascending order of row number ; Middle row number ; Set pair to store required cells ; Range of column number ; Store all cells of middle row within column number range ; Final step to store all the column number of 1 st and 3 rd cell upto MidRow ; Driver Code ; vector pair to store X , Y , Z
def Minimum_Cells ( v ) : NEW_LINE INDENT col = [ 0 ] * 3 NEW_LINE for i in range ( 3 ) : NEW_LINE INDENT column_number = v [ i ] [ 1 ] NEW_LINE col [ i ] = column_number NEW_LINE DEDENT col . sort ( ) NEW_LINE v . sort ( ) NEW_LINE MidRow = v [ 1 ] [ 0 ] NEW_LINE s = set ( ) NEW_LINE Maxcol = col [ 2 ] NEW_LINE MinCol = col [ 0 ] NEW_LINE for i in range ( MinCol , int ( Maxcol ) + 1 ) : NEW_LINE INDENT s . add ( ( MidRow , i ) ) NEW_LINE DEDENT for i in range ( 3 ) : NEW_LINE INDENT if ( v [ i ] [ 0 ] == MidRow ) : NEW_LINE INDENT continue ; NEW_LINE DEDENT for j in range ( min ( v [ i ] [ 0 ] , MidRow ) , max ( v [ i ] [ 0 ] , MidRow ) + 1 ) : NEW_LINE INDENT s . add ( ( j , v [ i ] [ 1 ] ) ) ; NEW_LINE DEDENT DEDENT return len ( s ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT v = [ ( 0 , 0 ) , ( 1 , 1 ) , ( 2 , 2 ) ] NEW_LINE print ( Minimum_Cells ( v ) ) NEW_LINE DEDENT