text: Pair having all other given pairs lying between its minimum and maximum | C # program for the above approach ; Function to find the position of the pair that covers every pair in the array [ , ] arr ; Position to store the index ; Stores the maximum second value ; Stores the minimum first value ; Iterate over the array of pairs ; Update right maximum ; Update left minimum ; Iterate over the array of pairs ; If any pair exists with value { left , right } then store it ; Print the answer ; Driver Code ; Given array of pairs ; Function Call
code: using System ; class GFG { static void position ( int [ , ] arr , int N ) { int pos = - 1 ; int right = int . MinValue ; int left = int . MaxValue ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i , 1 ] > right ) { right = arr [ i , 1 ] ; } if ( arr [ i , 0 ] < left ) { left = arr [ i , 0 ] ; } } for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i , 0 ] == left && arr [ i , 1 ] == right ) { pos = i + 1 ; } } Console . Write ( pos + " STRNEWLINE " ) ; } public static void Main ( String [ ] args ) { int [ , ] arr = { { 3 , 3 } , { 1 , 3 } , { 2 , 2 } , { 2 , 3 } , { 1 , 2 } } ; int N = arr . GetLength ( 0 ) ; position ( arr , N ) ; } }