Check If A String Has All Unique Character Without Using An Additional Data Structure (Episode - 1)

preview_player
Показать описание
In this video, we will see how to identify a string that has a unique character or not without using an additional data structure.
Before solving it we need to see whether the string is an ASCII string or Unicode String.
In my example I will consider ASCII string, One solution is to create an array of boolean values where the flag at index i indicate whether character i in the alphabet is contained in the string. The second time we see it this character we can immediately return false.
Рекомендации по теме
Комментарии
Автор

You are using the additional data structure but please go through the problem statement.

rajeshtalreja
Автор

My initial guess, if using C/C++, is to quicksort the characters in the string, then you scan through and look for successive characters that are equal.

Chalisque
Автор

you are using additional array to solve the problem, though the title says otherwise

abhilashvadnala
Автор

Sounds to me like one solution would be using two for loops .... for every character, look ahead in second for from the next byte/char to last and see if that character shows up again ... if it does, your string is not unique.
Another solution, if you're allowed to modify the original string, is to run a sort on it.. again, if you find two characters that are identical it's a bad string. You'll need a temporary variable to use to swap characters during sort, but that should be allowed, because you'll have temporary variables for the for loops anyway, no way around it.

mariushmedias
Автор

if you don't consider charcheck array as an additional data structure, why don't we go ahead and use HashSet instead.
1--> we traverse through the string and add every Character to the HashSet.
2--> so, HashSet doesn't allow duplictaes.
3--> after traversing we use an if Condition to check the Hash Set Size.
4--> if Hash Set size is equal to the length of the string we return true(which means there is no duplicates), else we return false(duplicates are present).
please reply .
is my method correct

abhiram
Автор

i didn’t understand the concept of adding static at 6:28
could you pls explain in what situations we need to add it and what situations we neednt?
thanks

shreyaskalnad
Автор

but the qstn is to not use extra space, u are still using extra space?

neghatnazir
Автор

what part of " Without Using An Additional Data Structure" is not clear ? you used Boolean Array !!

TheKillermob
Автор

bro can u bring a point of sale system or inventory system in swing please

aqibishaq
Автор

Yeah an array is a data structure. So that's terrible. You failed the interview. So sad. So bad.

xbzq