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 ; Driver Code ; Input string ; Calling Function
def printNum ( s ) : NEW_LINE INDENT i , j , val = 0 , 0 , 0 NEW_LINE mp = { } NEW_LINE val = ( ( ord ( s [ 0 ] ) - ord ( '0' ) ) * 100 + ( ord ( s [ 1 ] ) - ord ( '0' ) ) * 10 + ( ord ( s [ 2 ] ) - ord ( '0' ) ) ) NEW_LINE mp [ val ] = 1 NEW_LINE for i in range ( 3 , len ( s ) ) : NEW_LINE INDENT val = ( val % 100 ) * 10 + ord ( s [ i ] ) - ord ( '0' ) NEW_LINE if ( val in mp ) : NEW_LINE INDENT mp [ val ] = mp [ val ] + 1 NEW_LINE DEDENT else : NEW_LINE INDENT mp [ val ] = 1 NEW_LINE DEDENT DEDENT for m in mp : NEW_LINE INDENT key = m NEW_LINE value = mp [ m ] NEW_LINE if ( value > 1 ) : NEW_LINE INDENT print ( key , " ▁ - ▁ " , value , " ▁ times " ) NEW_LINE DEDENT DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT input = "123412345123456" NEW_LINE printNum ( input ) NEW_LINE DEDENT