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.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Efficiently check if a string has all unique characters without using any additional data structure
- Python - String with most unique characters
- Program to check if first and the last characters of string are equal
- Minimum deletions from string to reduce it to string with at most 2 unique characters
- Determine if a string has all Unique Characters
- Python | Ways to check string contain all same characters
- Python | Check if frequencies of all characters of a string are different
- Check if both halves of the string have same set of characters in Python
- 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
- Check if an encoding represents a unique binary string
- Python program to check if given string is pangram
- Python program to check if a string is palindrome or not
- Python program to check if a given string is Keyword or not
- Python program to check whether the string is Symmetrical or Palindrome
- Python program to check if given string is vowel Palindrome
- Check whether second string can be formed from characters of first string
- Check if both halves of the string have same set of characters
- Quick way to check if all the characters of a string are same
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.