Check if a string has all unique characters without using any additional data structure

preview_player
Показать описание
Finding if string contains unique characters seems to be very basic question, but when interviewer asks us to solve the question without using additional space then 80% students are not able to solve it.
Watch this video fully to learn how to solve it and see as i explain the code and dry run the code to explain the bitwise operates and why and how they are used in the program and how left shift and 'and' and 'or' works in case of bitwise.

If you like the video, consider subscribing to the channel for instant updates.

Follow me on social media:
Рекомендации по теме
Комментарии
Автор

But you are still using another data structure. In this case it’s a bit set. That’s all. There is a nice article on bitsets in John bentelys programming pearls where he sorts a telephone directory with minimal memory

ramn
Автор

You are using an additional data structure. Without an additional data structure, it won't be possible to do it in O(n) time. Even if we use a Set, it will take constant space as we only have a fixed number of characters in ASCII system.

devanshmaurya
Автор

What is the time complexity of this approach ?

ShreyaSingh-vrqi
Автор

But it still using a another data structure right, making space complexity O(N).

garumugam
Автор

will this be correct in java ? i iterate over the char array and find the lastIndex of the char in string like "i love
.
Now if there's any difference between i and lastIndex that will mean that the string is containing duplicates.

Please reply.. I would like to learn more about the same

ramangarg
Автор

If I take an unordered_map then also it won't make much difference

AnikashChakraborty
Автор

What if there are characters apart from alphabets. Then how to do it.

miewtoe