Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork5.7k
algorithm: letter combinations#1209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
algorithm: letter combinations#1209
Uh oh!
There was an error while loading.Please reload this page.
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
How is this a backtracking problem? At first glance this appears to be a simple combinatorial problem: Finding the cross product of the sets of possible letters for all numbers.
hiitesh1127 commentedOct 19, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@appgurueu Sir you are correct when there are just two digits in the provided string, but if we analyze the scenario of three digits, we notice that we need to backtrack for the second digit string. |
appgurueu commentedOct 19, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I wrote the following solution which got accepted in Go: funcletterCombinations(digitsstring) []string {ifdigits=="" {return []string{} }letters:= [8]string{"abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"}res:= []string{""}for_,digit:=rangedigits {nextRes:= []string{}for_,letter:=rangeletters[digit-'2'] {for_,str:=rangeres {nextRes=append(nextRes,str+string(letter)) } }res=nextRes }returnres} this problem does not inherently require recursion or backtracking? As said, it's just the cartesian product |
hiitesh1127 commentedOct 19, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Okay Sir, I guess your solution is iterative and mine is recursive https://www.interviewbit.com/blog/letter-combinations-of-a-phone-number/ |
appgurueu commentedOct 19, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
- fromhttps://en.wikipedia.org/wiki/Backtracking I don't see how this definition is met - no "candidates" are "abandoned" (if I'm missing something, please explain). All I see is a simple combinatorial algorithm. LeetCode and InterviewBit are probably getting their terminology wrong.@raklaptudirm your opinion? Should this go under "Backtracking" or just "Recursion"? In the Lua repo I prefer to categorize algorithms not by the applied "strategy", but rather strictly by the problem they solve. |
Please review@raklaptudirm |
I guess recursive would be best. |
Okay I will update |
Uh oh!
There was an error while loading.Please reload this page.
It is one of the most common Backtracking Problems asked during interviews
Describe your change:
Checklist:
Example:
UserProfile.js
is allowed butuserprofile.js
,Userprofile.js
,user-Profile.js
,userProfile.js
are notFixes: #{$ISSUE_NO}
.