Check whether a given string is Heterogram or not | PHP Program to check whether the given string is Heterogram or not . ; traversing the string . ; ignore the space ; if already encountered ; else return false . ; Driven Code
< ? php function isHeterogram ( $ s , $ n ) { $ hash = array ( ) ; for ( $ i = 0 ; $ i < 26 ; $ i ++ ) $ hash [ $ i ] = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { if ( $ s [ $ i ] != ' ▁ ' ) { if ( $ hash [ ord ( $ s [ $ i ] ) - ord ( ' a ' ) ] == 0 ) $ hash [ ord ( $ s [ $ i ] ) - ord ( ' a ' ) ] = 1 ; else return false ; } } return true ; } $ s = " the ▁ big ▁ dwarf ▁ only ▁ jumps " ; $ n = strlen ( $ s ) ; if ( isHeterogram ( $ s , $ n ) ) echo ( " YES " ) ; else echo ( " NO " ) ; ? >