Maximum Length of a Concatenated String with Unique Characters

preview_player
Показать описание
----------------------------------------------------------------------------------------------------------------

MUSIC
----------------------------------------------------------------------------------------------------------------
look at me. by ☽shinji☾
Рекомендации по теме
Комментарии
Автор

wouldn't it be much faster converting all to a set - if it's size is longer than the initial one - throw it our right away - otherwise do it with all permutations?

PhotovolMike
Автор

At 1:29, would the string un+ue be considered a concatenation?

mostinho
Автор

10:05 We loop through the original array (left to right), and at each step we simulate concatenating the item we’re on to our string or not concatenating it (skipping it)

mostinho
Автор

So what is like a good indicator of 'Use DFS or BFS on this problem?' Like where exactly do you use DFS in this problem?

jaychally
Автор

Shouldn't the helper function being considered when calculating the time complexity?
I think the time complexity should be O(w*2^n) where w is the average length of words and n is the number of words

dyyfkdyyfk
Автор

SLIGHT HICCUP ! only strings that have unique characters can be added so before adding a string check if it has unique characters itself and with the string already formed . this way at an average 50 % recursive calls would be saved

rushilthareja
Автор

The complexity can be improved if you don't make those two calls always but based on condition. If characters from the array[index] are already present in current, then calling backtrack function with the next index and same Current string would be the case and otherwise call the backtrack function would be with the next index and Current + array[index].

piyushdoke
Автор

This is a dynamic programming question, not a "Classical DFS" as mentioned at 3:39. It can be solved either through tabulation or memoization. The solution presented here is sub-optimal because it duplicates a significant amount of work.

jamesh
Автор

Are you saying this is 2^n runtime? If yes, is it not too slow? Can you tell whether I understood right?

vigneshmohan
Автор

What i most like in your videos is just the fact how you explain things kind of complicated in a easy way... i feel like i can finally understand things in the same way i feel a overwhelming will for learn more and more.. thanks for sharing your knowledge. Big hug from Brazil

joaonascimento
Автор

Kevin ! why dont we use an int variable instead of using int array of a unit size ?

mandeepbahal
Автор

Kevin, great explanation. Thanks!
I'd suggest to improve time complexity by:
1. don't call recursion if the string already has duplications;
2. use memoization inside uniqueCharCount function.
Improve the space complexity a little bit by using 4byte int instead of array of 26 integers:
int length = 0;
int binaryRepresentation = 0;
for (char c : current.toCharArray()) {
int shift = 1;
shift <<= c - 'a';
if ((binaryRepresentation & shift) != 0) {
return -1;
} else {
binaryRepresentation |= shift;
length++;
}
}

What do you say?

romanesterkin
Автор

Can you please explain why you used an array of size 1 instead of maintaining a single integer variable?

madhavchittlangia
Автор

I tried to use an integer to keep track of the maximum length, and the output is 0. Can you tell me why it doesn't work? (I used for exact code besides the result array)

joseph
Автор

I don’t think he explained the reason for two recursive call .. he just read the code. Any one else(perhaps who thanked for the video) can explain here

sundarkris
Автор

Hi kevin why we are storing result in an array instead of an integer

aronblanche
Автор

nice video! thank you for explaining the recursive solution. Could you elaborate more on why we need the first recursive call? I didn't get that part

sarahjeffry
Автор

May I ask why you decided to use an integer array of one item over a single integer variable?

samuelalvarado
Автор

Hey Kevin! Question - I don't think you recall why we need to simulate both the recursive calls, whats the purpose of not adding to current?

rahulchawla
Автор

Hey are you solving premium leetcode questions in your playlists of specific companies?

jaynilgaglani