Check if a string is Isogram or not | CPP code to check string is isogram or not ; function to check isogram ; loop to store count of chars and check if it is greater than 1 ; if count > 1 , return false ; Driver code ; checking str as isogram ; checking str2 as isogram
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool check_isogram ( string str ) { int length = str . length ( ) ; int mapHash [ 26 ] = { 0 } ; for ( int i = 0 ; i < length ; i ++ ) { mapHash [ str [ i ] - ' a ' ] ++ ; if ( mapHash [ str [ i ] - ' a ' ] > 1 ) { return false ; } } return true ; } int main ( ) { string str = " geeks " ; string str2 = " computer " ; if ( check_isogram ( str ) ) { cout << " True " << endl ; } else { cout << " False " << endl ; } if ( check_isogram ( str2 ) ) { cout << " True " << endl ; } else { cout << " False " << endl ; } return 0 ; }