![]() |
VOOZH | about |
Given a word or phrase, check if it is an isogram or not. An Isogram is a word in which no letter occurs more than once
Examples:
Input: Machine
Output: True
Explanation: "Machine" does not have any character repeating, it is an IsogramInput : Geek
Output : False
Explanation: "Geek" has 'e' as repeating character, it is not an Isogram
To solve the problem follow the below idea:
Sort the string and for every character check, if the current character is equal to the previous character or not. If it is equal then the string is not an isogram
Follow the given steps to solve the problem:
Below is the implementation of the above approach:
True True False False
Time Complexity: O(N log N)
Auxiliary Space: O(1)
To solve the problem follow the below idea:
In this, the count of characters of the string is stored in the hashmap, and wherever it is found to be greater than 1 for any char, return false else return true at the end
Follow the given steps to solve the problem:
Below is the implementation of the above approach:
False True
Time Complexity: O(N)
Auxiliary Space: O(1), as an array of fixed size 26 is used.
Thanks Sahil Bansal for suggesting the above method.
If you like GeeksforGeeks (We know you do!) and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to review-team@geeksforgeeks.org.