please give the flow of this prgm
Phone keypad recursion
Suppose we are given a string of numbers, eg: “23425” and we have to get the possible strings we can get. We use backtracking here because at every number we get in the string we have some characters from which we can choose to put in the final answer. For eg, ‘2’ maps “abc”, 3 maps “def”, 4 maps “ghi”, 5 maps “jkl”.
Now, we can use a recursive function like below:
Here, m is the map that maps every integer to string of possible characters and curr is the string that is one of the possible strings we can get and ans is the vector consisting of all possible strings, It will be more beneficial if you try this out yourself first and then ask if there’s any problem,
void sol(string A,string &curr, int i,int l){
if(i==l){
ans.push_back(curr);
return;
}
char c = A[i];
string doom = m[c];
for(auto ch:doom){
curr.push_back(ch);
sol(A,curr,i+1,l);
curr.pop_back();
}
}
If this helped you, kindly resolve this doubt and rate the reply, helps us a lot!