pranay_teja
9/16/2018 - 9:05 AM

GFG Check if a string is Isogram or not

#include <bits/stdc++.h>
using namespace std;

// #Maps #Hashing #GFG #Problem
// https://practice.geeksforgeeks.org/problems/check-if-a-string-is-isogram-or-not/0/?track=SP-Hashing

bool isIsogram(string x){
    map < char, bool > m;
    for(int i=0;i<x.size();i++){
        if( m[ x[i] ]==true ){
            return false;   // if char is repeated return false
        }
        m[ x[i] ]=true;
    }
    return true;
}

int main() {
	int t;
	cin>>t;
	while(t--){
	    string x;
	    cin>>x;
	    if(isIsogram(x)==true){
	        cout<<"1"<<endl;
	    }else{
	        cout<<"0"<<endl;
	    }
	}
	return 0;
}