To implement an algorithm to determine if a string contains all unique characters.
Input : s = “abcd”
“abcd” doesn’t contain any duplicates. Hence the output is True.
Input : s = “abbd”
“abbd” contains duplicates. Hence the output is False.
One solution is to create an array of boolean values, where the flag at the index i indicates whether character i in the alphabet is contained in the string. The second time you see this character you can immediately return false.
You can also return false if the string length exceeds the number of unique characters in the alphabet.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Efficiently check if a string has all unique characters without using any additional data structure
- Determine if a string has all Unique Characters
- Check if a String contains any index with more than K active characters
- Check if a string contains uppercase, lowercase, special characters and numeric values
- Minimum deletions from string to reduce it to string with at most 2 unique characters
- Smallest window that contains all characters of string itself
- String matching where one string contains wildcard characters
- Python program to Sort a List of Strings by the Number of Unique Characters
- Python - String with most unique characters
- Python program to print k characters then skip k characters in a string
- Count of all unique substrings with non-repeating characters
- String with maximum number of unique characters
- Minimize number of unique characters in string
- Find the longest substring with k unique characters in a given string
- Minimum Cost of deletions such that string does not contains same consecutive characters
- Minimum number of operations to move all uppercase characters before all lower case characters
- Check if given string contains all the digits
- Check if a binary string contains all permutations of length k
- Min flips of continuous characters to make all characters same in a string
- Program to check if a string contains any special character
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.