text: Find the two numbers with odd occurrences in an unsorted array | Prints two numbers that occur odd number of times . The function assumes that the array size is at least 2 and there are exactly two numbers occurring odd number of times . ; Create map and calculate frequency of array of * elements using array . ; Traverse through the map and check if its second element that is the frequency is odd or not . Then this is the odd occurring element . Its is clearly mentioned in problem that there are only two odd occurring elements so this will print those two elements . ; Driver code
code: function printTwoOdd ( arr , size ) { let m = new Map ( ) ; for ( let i = 0 ; i < size ; i ++ ) { if ( m . has ( arr [ i ] ) ) { m . set ( arr [ i ] , m . get ( arr [ i ] ) + 1 ) } else { m . set ( arr [ i ] , 1 ) } } document . write ( " " ) ; let ar = [ ] for ( let x of m ) { if ( x [ 1 ] % 2 != 0 ) ar . push ( x [ 0 ] ) } document . write ( ` ${ ar . reverse ( ) } ` ) } let arr = [ 4 , 2 , 4 , 5 , 2 , 3 , 3 , 1 ] ; let arr_size = arr . length ; printTwoOdd ( arr , arr_size ) ;