Print all 3 digit repeating numbers in a very large number | function to print 3 digit repeating numbers ; Hashmap to store the frequency of a 3 digit number ; first three digit number ; if key already exists increase value by 1 ; Output the three digit numbers with frequency > 1 ; Input string ; Calling Function
function printNum ( s ) { let i = 0 , j = 0 , val = 0 ; let hm = new Map ( ) ; val = ( s [ 0 ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) * 100 + ( s [ 1 ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) * 10 + ( s [ 2 ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) ; hm . set ( val , 1 ) ; for ( i = 3 ; i < s . length ; i ++ ) { val = ( val % 100 ) * 10 + s [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ; if ( hm . has ( val ) ) { hm . set ( val , hm . get ( val ) + 1 ) ; } else { hm . set ( val , 1 ) ; } } for ( let [ Key , Value ] of hm . entries ( ) ) { let key = Key ; let value = Value ; if ( value > 1 ) document . write ( key + " " + value + " " ) ; } } let input = " " ; printNum ( input ) ;