problem no 65: check if the string is isogram or not.
problem:
Given a string S of lowercase alphabets, check if it is isogram or not. An Isogram is a string in which no letter occurs more than once.
Example 1:
Input:
S = machine
Output: 1
Explanation: machine is an isogram
as no letter has appeared twice. Hence
we print 1.
Example 2:
Input:
S = geeks
Output: 0
Explanation: geeks is not an isogram
as 'e' appears twice. Hence we print 0.
Your Task:
This is a function problem. You only need to complete the function isIsogram() that takes a string as a parameter and returns either true or false.
code:
bool isIsogram(string s)
{
unordered_map<char,int> mapp;
for(char element:s)
{
mapp[element]++;
}
int flagforisogram=1;
for(auto ele:mapp)
{
if(ele.second>1)
{
flagforisogram=0;
}
}
if(flagforisogram==1)
{
return true;
}
else
{
return false;
}
}
Comments
Post a Comment