LeetCode Letter Combinations of a Phone Number Solution Explained - Java

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


Preparing For Your Coding Interviews? Use These Resources
————————————————————

Other Social Media
----------------------------------------------

Show Support
------------------------------------------------------------------------------

#coding #programming #softwareengineering
Рекомендации по теме
Комментарии
Автор

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(); \n for (int j = 0; j < size; j++) { // rest of code goes here }

crisag.
Автор

Can you slow down a Lil and explain the solution before you type code?

someoneanonymous
Автор

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.

anubhavnegi
Автор

i don't understand why we are using a linkedlist, not a arraylist or just a queue directly?

sophiezhang
Автор

I also solved it using a queue. You are doing a really great job man, you can describe what you are thinking excellent.

dincerbeken
Автор

I dont understand for sytax C++ because it has different function. Can transale someone for C . THANKS...

hasan
Автор

Solution : private static final String[] MAPPINGS = {"0", "1", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};

public static List<String> letterCombinations2(String digits) {
List<String> 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<String> 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);
}
}

poorpanda
Автор

You are genius Nick. I was stuck on this problem using the usual backtracking method of But your method is awesome. Can you please explain when to use the normal backtracking method and when to avoid it.?

svdfxd
Автор

Thank you so much! This solution is so smart, and your explanation is clear.

gu
Автор

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 !!!

KumarKaran-AI
Автор

Why don't we use a map instead of a String array 2:50

sparrow
Автор

Hey Nick ! You are my idol
i really a big fan of your crazy logic
keep going Dude!...

rohitrohilla
Автор

OutputArr.peek().length() how it will work at length =0?

parthsoni
Автор

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!

KaranNagi
Автор

bro that was helping, It's a queue solution

سهيلهأيوب-سه
Автор

Nicely explained. The stdouts help us understand the solution better. Love all your videos.

Rdharini
Автор

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?

freefortravel
Автор

I think this is combination problem, not permutation problem. CMIIW.

fajriillahi
Автор

Hello guys, please anyone knows a group for developers where you can belong and grow in experience?

Matthew-hhex
Автор

Surprised there isn’t a slick technique available

zo