Recursion-codes of the string :code passes sample case but fails all test cases

https://hack.codingblocks.com/contests/c/452/346

#include<bits/stdc++.h>

using namespace std;

vectorv;
void codes(string in ,string out)
{
if(in.size()==1)
{

	v.push_back(out+(char)((int)(in.at(0) -'0'+ 'a') -1));
return;
}

codes(in.substr(1),out+(char)((int)(in.at(0) -'0'+ 'a') -1));
if(in.size()==2)
{
	v.push_back(out+(char)((int)( (in.at(0) -'0')*10+ in.at(1) -'0' +'a') -1));
	return;
} 

if( (in[0]-'0')*10+(in[1]-'0')<=26){
if(in.size()>2)
codes(in.substr(2),out+(char)((int)( (in.at(0) -'0')*10+ in.at(1) -'0' +'a') -1) );
else if(in.size()==2)
	v.push_back(out+(char)((int)( (in.at(0) -'0')*10+ in.at(1) -'0' +'a') -1));

}
}

int main(){
string inp;
cin>>inp;
codes(inp,"");
cout<<"["; copy(v.begin(),v.end(),ostream_iterator(cout,", “)) ;cout<<”\b\b]";
}
This code is passing the sample case. And even some of my own test cases.
In the question it mentioned that the the recursive func should return arraylist ,is it because of this?

Hey Vikalp ! actually your code is giving runerror and not printing anything . so you first need to debug the code. even after that if you find problems , you can go through this code which i modified ur code. :wink:
https://ide.codingblocks.com/#/s/13333

1 Like

With the help of your code I edited my code to this : link

This is still not passing the test cases. Even your solution didn’t pass!
plz chk

Sorry for the inconvinience Vikalp, you can try with this. This is perfect. https://ide.codingblocks.com/#/s/13987

1 Like