Smart keypad advanced doubt

plz check my code where i am wrong

code-> https://ide.codingblocks.com/s/99192

ques-> https://online.codingblocks.com/player/24179/content/4669/4742

hey @yatin, you have to consider the special case when digit =1 or digit =1. Moreover you are getting runtime error due to subsequence function. As you are using string there is find function which will do the work of subsequence function.(http://www.cplusplus.com/reference/string/string/find/).You ran a loop till 10 it should be till 11.
I have made changes to your code you can check them here https://ide.codingblocks.com/s/99204

i understood completely what u said sirr
what does find function return if our substring is not present in the parent string??

hey @yatin, it will return -1.

in my code i did if find function returns any value >0
then all the names are printing infintely
y
so i wrote if it returns <1000
then print my string
i got all test cases passed but y so

0 is not working there y?

1 Like

hey @yatin, -1 in also included in <1000, you should only print the answer for all value returned by find(), except -1. The code I shared you earlier has that condition too.

sir i m getting correct answer for <1000

sir just cout<< parentring.find(substring)
if substring is not present it should give -1
but output is very large value

plzz check it once

hey @yatin, yes you are write. It will return a long number instead of -1.
Check this code, read from lines 6-11 https://ide.codingblocks.com/s/99726

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

Passed

#include<bits/stdc++.h>
using namespace std;
vector<string> arr;
string searchIn [] = {
            "prateek", "sneha", "deepak", "arnav", "shikha", "palak",
            "utkarsh", "divyam", "vidhi", "sparsh", "akku"
    };
string table[] = { " ", ".+@$", "abc", "def", "ghi", "jkl" , "mno", "pqrs" , "tuv", "wxyz" };

void helper(string input, string output)
{
	if(input.length()==0)
	{
		arr.push_back(output);
		return;
	}
	string temp = table[input[0]-'0'];
	for(int i=0; i<temp.length(); i++)
		helper(input.substr(1), output + temp[i]);
}

int main() {
	string str; cin>>str;
	helper(str, "");
	for(int i=0; i<11; i++)
	{
		for(auto j: arr)
		{
			if(searchIn[i].find(j)!=string::npos)
				cout<<searchIn[i]<<endl;
		}
	}
	// for(int i=0; i<11; i++)
	// 	cout<<reff[i]<<" ";
	// cout<<endl;
	return 0;
}