#include<bits/stdc++.h>
using namespace std;
void replacei(string & s,string & t,int i=0){
t=t+s[i];
if(i==s.length()-1)return ;
if(s[i]==s[i+1])t=t+’*’;
replacei(s,t,i+1);
}
int main(){
string s=“allahabad”,t="";
replacei(s,t);
cout<<t;
return 0;
}
In this question if we do s[i]=="\0",instead of i==s.length()-1),its not passing test cases
#include<bits/stdc++.h>
using namespace std;
void replacei(string & s,string & t,int i=0){
t=t+s[i];
if(s[i]=='\0')return ;
if(s[i]==s[i+1])t=t+'*';
replacei(s,t,i+1);
}
int main(){
string s="allahabad",t="";
cin>>s;//added this
replacei(s,t);
t.pop_back();//because null is also added to string that should not cause an issue but idk its causing here
cout<<t;
return 0;
}
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.
Thanks ,I am satisfied with the answer
1 Like