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

Popular posts from this blog

problem no 18: number of buildings that can see the sun . ( or facing the sun.)

problem no 7:Given two numbers A and B, find Kth digit from right of AB.

problem 3: given two integers N and M. The problem is to find the number closest to N and divisible by M. If there are more than one such number, then output the one having maximum absolute value.