Find index of the element differing in parity with all other array elements | C # program for the above approach ; Function to print the array element which differs in parity with the remaining array elements ; Multimaps to store even and odd numbers along with their indices ; Traverse the array ; If array element is even ; Otherwise ; If only one even element is present in the array ; If only one odd element is present in the array ; Driver Code ; Given array ; Size of the array
using System ; using System . Collections . Generic ; using System . Linq ; class GFG { static void OddOneOut ( int [ ] arr , int N ) { Dictionary < int , int > e = new Dictionary < int , int > ( ) ; Dictionary < int , int > o = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] % 2 == 0 ) { e [ arr [ i ] ] = i ; } else { o [ arr [ i ] ] = i ; } } if ( e . Count == 1 ) { Console . Write ( e . First ( ) . Value ) ; } else { Console . Write ( o . First ( ) . Value ) ; } } public static void Main ( string [ ] args ) { int [ ] arr = { 2 , 4 , 7 , 8 , 10 } ; int N = arr . Length ; OddOneOut ( arr , N ) ; } }