educative.io

Solution Review: Is Unique

All the provided solutions fails if I update the input string to :
unique_str = “AbCDefG”
to
unique_str = “Ab CD efG”

In the implementation, wouldn’t it be better to get rid of all spaces and converting all characters into lowercase?


Course: Data Structures and Algorithms in Python - AI-Powered Learning for Developers
Lesson: Solution Review: Is Unique - Data Structures and Algorithms in Python


Course: Data Structures and Algorithms in Python - AI-Powered Learning for Developers
Lesson: Solution Review: Is Unique - Data Structures and Algorithms in Python

Hi @Kshitij_Jindal!!
In the problem statement, it is mentioned that the input string will only contain alphabets or spaces. However, the provided solution will give false when the input string contains the same character more than once. When you change the input string from input_str = "AbCDefG" to input_str = "Ab CD efG" , it now contains two spaces. As a result, the solution will return false.
And the problem statement explicitly mentions that the input string can contain both alphabets and spaces, there’s no need to remove spaces from the input string. Removing spaces would alter the input and potentially lead to incorrect results.
I hope it helps. Happy Learning