Check whether a given string is Heterogram or not | Java Program to check whether the given string is Heterogram or not . ; traversing the string . ; ignore the space ; if already encountered ; else return false . ; Driver code
class GFG { static boolean isHeterogram ( String s , int n ) { int hash [ ] = new int [ 26 ] ; for ( int i = 0 ; i < n ; i ++ ) { if ( s . charAt ( i ) != ' ▁ ' ) { if ( hash [ s . charAt ( i ) - ' a ' ] == 0 ) hash [ s . charAt ( i ) - ' a ' ] = 1 ; else return false ; } } return true ; } public static void main ( String [ ] args ) { String s = " the ▁ big ▁ dwarf ▁ only ▁ jumps " ; int n = s . length ( ) ; if ( isHeterogram ( s , n ) ) System . out . print ( " YES " ) ; else System . out . print ( " NO " ) ; } }