Find frequency of each character with positions in given Array of Strings | Function to print every occurence of every characters in every string ; Iterate over the vector arr [ ] ; Traverse the string arr [ i ] ; Push the pair of { i + 1 , j + 1 } in mp [ arr [ i ] [ j ] ] ; Print the occurences of every character ; Input ; Function call
function printOccurences ( arr , N ) { let mp = new Map ( ) ; for ( let i = 0 ; i < N ; i ++ ) { for ( let j = 0 ; j < arr [ i ] . length ; j ++ ) { if ( mp . has ( arr [ i ] [ j ] ) ) { let temp = mp . get ( arr [ i ] [ j ] ) ; temp . push ( [ i + 1 , j + 1 ] ) ; mp . set ( arr [ i ] [ j ] , temp ) ; } else { mp . set ( arr [ i ] [ j ] , [ [ i + 1 , j + 1 ] ] ) ; } } } for ( let it of new Map ( [ ... mp . entries ( ) ] . sort ( ) ) ) { document . write ( " " + it [ 0 ] + " " ) ; for ( let j = 0 ; j < it [ 1 ] . length ; j ++ ) { document . write ( " " + it [ 1 ] [ j ] [ 0 ] + " " + it [ 1 ] [ j ] [ 1 ] + " " ) ; } document . write ( " " ) ; } } let arr = [ " " , " " ] ; let N = arr . length ; printOccurences ( arr , N ) ;