Is it an isogram?
- O(n log n) · Hard
- Full plan
- Python
- JavaScript
- strings
- sorting
- booleans
Problem
An isogram is a word that repeats no letter: "background" is one, "banana" is not, because the a arrives three times and the n twice.
Write a function that takes a text and returns true if it is an isogram and false if it is not.
The rules: uppercase and lowercase count as the same letter, so "Bob" is not an isogram. Spaces and hyphens are not letters: even if they repeat, they do not get in the way. With an empty text you return true, because there is no repeated letter.
You can compare every letter with all the others, but there is a shorter road: sort the letters and check only neighbors, because two equal letters always end up side by side.
Examples
Nothing repeated
"background" → true
With a repeated letter
"banana" → false
Uppercase and lowercase
"Bob" → false
With hyphens
"red-hot-jam" → true
Besides these, the challenge has hidden tests that are revealed when you submit your solution.
You start with this
Python
def is_isogram(text):
passJavaScript
function isIsogram(text) {
}It opens in your browser, with the editor and the tests. This challenge is part of the full plan; the O(1) and O(log n) ones are free.