Minimum Numbers of cells that are connected with the smallest path between 3 given cells | C # implementation of the approach ; 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 ; vector pair to store X , Y , Z
using System ; using System . Collections . Generic ; class GFG { static int Minimum_Cells ( List < Tuple < int , int > > v ) { int [ ] col = new int [ 3 ] ; int i , j ; for ( i = 0 ; i < 3 ; i ++ ) { int column_number = v [ i ] . Item2 ; col [ i ] = column_number ; } Array . Sort ( col ) ; v . Sort ( ) ; int MidRow = v [ 1 ] . Item1 ; HashSet < Tuple < int , int > > s = new HashSet < Tuple < int , int > > ( ) ; int Maxcol = col [ 2 ] , MinCol = col [ 0 ] ; for ( i = MinCol ; i <= Maxcol ; i ++ ) { s . Add ( new Tuple < int , int > ( MidRow , i ) ) ; } for ( i = 0 ; i < 3 ; i ++ ) { if ( v [ i ] . Item1 == MidRow ) continue ; for ( j = Math . Min ( v [ i ] . Item1 , MidRow ) ; j <= Math . Max ( v [ i ] . Item1 , MidRow ) ; j ++ ) { s . Add ( new Tuple < int , int > ( j , v [ i ] . Item1 ) ) ; } } return s . Count ; } static void Main ( ) { List < Tuple < int , int > > v = new List < Tuple < int , int > > ( ) ; v . Add ( new Tuple < int , int > ( 0 , 0 ) ) ; v . Add ( new Tuple < int , int > ( 1 , 1 ) ) ; v . Add ( new Tuple < int , int > ( 2 , 2 ) ) ; Console . Write ( Minimum_Cells ( v ) ) ; } }