Awesome video thank you Nick! To anyone who was a little confused at the while loop condition "while (output_array.peek().length() == i)", another way to do this is to capture the size of the queue at the moment in time in a variable, and then open up another for loop. So instead of doing this "while (output_array.peek().length() == i)" you could do this --> int size = output_array.size(); for (int j = 0; j < size; j++) { // rest of code goes here }
for anyone wondering linked list is better use than arraylist here cuz we need to manipulate the data also ( linked list can act as a queue as well as a list) whereas arraylist only act as a list.
You are genius Nick. I was stuck on this problem using the usual backtracking method of choose-explore(recursive)-unchoose. But your method is awesome. Can you please explain when to use the normal backtracking method and when to avoid it.?
Excellent videos @nick. Can you please please share a video on Combination Sum II and subset II. Get a little confused on why is increase the depth by 1 in these cases and not in cases of Combination Sum and subset?
i was asked the same question in Amazon online coding with an engineer, i solved the question by generating all the permutations, however the engineer asked me to optimize the code, and I was not able to think of anything, don't know if i will clear it. If anyone knows how to optimize this solution let me know. Cheers!
I think there is no way to optimize the time complexity. After all, you need to permutate every possibility and that's actually the time complexity here. I think the interviewer is looking for a "no" to this question.
@@mliu7712 I mean in the video it shows that nick's solution was only faster than ~64% of submissions. Best way to find those solutions would be to look at the analytics of the question on YT and look at the fastest solution
you've generated permutations, but you only need combinations, that is still exponential time, but a bit better then permutations. The reason you need only combinations is because every letter of a specific number can be at the same idx, so ad,ae,af are all valid, however, you do not need the permutation of these like ea, da, fa
because he adds an empty string to the linked list, so whenever he checks the first time, variable "i" will be 0 and the length of the empty string is equal to 0, so they are equal
Bro can you please tell me if this solution is generating combinations of more than size 2 Like If I have 3245 , then will this solution give me combinations of length 4?
Awesome video thank you Nick! To anyone who was a little confused at the while loop condition "while (output_array.peek().length() == i)", another way to do this is to capture the size of the queue at the moment in time in a variable, and then open up another for loop. So instead of doing this "while (output_array.peek().length() == i)" you could do this --> int size = output_array.size();
for (int j = 0; j < size; j++) { // rest of code goes here }
it's a bit slower(according to Leetcode)
Can you slow down a Lil and explain the solution before you type code?
for anyone wondering linked list is better use than arraylist here cuz we need to manipulate the data also ( linked list can act as a queue as well as a list) whereas arraylist only act as a list.
i don't understand why we are using a linkedlist, not a arraylist or just a queue directly?
LinkedList implements the Queue interface, it implements a number of different data structures in Java actually
I also solved it using a queue. You are doing a really great job man, you can describe what you are thinking excellent.
You are genius Nick. I was stuck on this problem using the usual backtracking method of choose-explore(recursive)-unchoose. But your method is awesome. Can you please explain when to use the normal backtracking method and when to avoid it.?
this problem can be solved with backtracking.
I dont understand for sytax C++ because it has different function. Can transale someone for C . THANKS...
Solution : private static final String[] MAPPINGS = {"0", "1", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
public static List letterCombinations2(String digits) {
List result = new ArrayList();
if (digits.length() == 0) {
return result;
}
helper(digits, 0, "", result);
return result;
}
private static void helper(String digits, int index, String combinations, List result) {
if (index == digits.length()) {
result.add(combinations);
return;
}
String letters = MAPPINGS[digits.charAt(index) - '0'];
// toCharArray() -> converts the given string into a sequence of characters.
for (char letter : letters.toCharArray()) {
helper(digits, index + 1, combinations + letter, result);
}
}
Thank you so much! This solution is so smart, and your explanation is clear.
Thanks Nick, you are doing a great job.
Your videos are very helpful for people like us.
Thanks a lot Mate! Wish you all Success !!!
Why don't we use a map instead of a String array 2:50
Hey Nick ! You are my idol
i really a big fan of your crazy logic
keep going Dude!...
Excellent videos @nick. Can you please please share a video on Combination Sum II and subset II. Get a little confused on why is increase the depth by 1 in these cases and not in cases of Combination Sum and subset?
i was asked the same question in Amazon online coding with an engineer, i solved the question by generating all the permutations, however the engineer asked me to optimize the code, and I was not able to think of anything, don't know if i will clear it. If anyone knows how to optimize this solution let me know. Cheers!
I think there is no way to optimize the time complexity. After all, you need to permutate every possibility and that's actually the time complexity here. I think the interviewer is looking for a "no" to this question.
@@mliu7712 I mean in the video it shows that nick's solution was only faster than ~64% of submissions. Best way to find those solutions would be to look at the analytics of the question on YT and look at the fastest solution
you've generated permutations, but you only need combinations, that is still exponential time, but a bit better then permutations.
The reason you need only combinations is because every letter of a specific number can be at the same idx, so ad,ae,af are all valid, however, you do not need the permutation of these like ea, da, fa
I think this is combination problem, not permutation problem. CMIIW.
Nicely explained. The stdouts help us understand the solution better. Love all your videos.
bro that was helping, It's a queue solution
awesome solution !
OutputArr.peek().length() how it will work at length =0?
because he adds an empty string to the linked list, so whenever he checks the first time, variable "i" will be 0 and the length of the empty string is equal to 0, so they are equal
Surprised there isn’t a slick technique available
This is a very different and beautiful solution .
Hello guys, please anyone knows a group for developers where you can belong and grow in experience?
Did u find any?
Great as always
Nice..thanks for this. Please can you explain the time and space complexity
while(letterGeneration.peek().length() == i) is soooo clever
I had trouble understanding this. If anyone could give a more detailed explanation it would be appreciated.
Please make video on sorted permutation rank problem. with and without repetition.
can you solve subsets problem 46 from leetcode please ?
thank you!
what is the time/space complexity here?
Great
omg, nick didn't clap
Bro can you please tell me if this solution is generating combinations of more than size 2
Like If I have 3245 , then will this solution give me combinations of length 4?
yes it does.
sorry its permutation-46.
Aah.. nice.. thanks..