RECURSION-OBEDIENT STRING some test cases giving wrong ans

link to ques–https://hack.codingblocks.com/contests/c/457/348

#include
#include
using namespace std;

bool check(string a,int i);
int main()
{
string a;
cin>>a;

bool ans=check(a,0);
if(ans)cout<<"true";
else cout<<"false";

}

bool check(string a,int i)
{

if(a[i]=='\0')
	return true;

if(i==0)
{
	if(a[i]!='a')
		return false;
}

if(a[i]=='a')
{
	if(!(a[i+1]=='\0'||(a[i+1]=='b'&& a[i+2]=='b') ))
		return false;
}

if(a[i]=='b'&& a[i+1]=='b')
{
	if(!(a[i+2]=='\0'||a[i+2]=='a'))
		return false;
	
}

if(check(a,i+1))
	return true;

}

shagun
1…a can be also followed by a
2…if there are two b then u have to make a recursive call form the last b that is
abba if u encounter first b then recursive call should be start from a not from second b.

if u get any futher problem refer my code
https://ide.codingblocks.com/#/s/16113

sir i made the two changes you pointed but the code still wont work…could you please tell me whats wrong with my code

#include
#include
using namespace std;

bool check(string a,int i);
int main()
{
string a;
cin>>a;

bool ans=check(a,0);
if(ans)cout<<"true";
else cout<<"false";

}

bool check(string a,int i)
{

if(a[i]=='\0')
	return true;

if(i==0)
{
	if(a[i]!='a')
		return false;
}

if(a[i]=='a')
{
	if(!(a[i+1]=='\0'||(a[i+1]=='b'&& a[i+2]=='b') || (a[i+1]=='a')))
		return false;
}

if(a[i]=='b')
if(a[i+1]=='b')
{
	if(!(a[i+2]=='\0'||a[i+2]=='a'))
		return false;
	i=i+1;
}

if(check(a,i+1))
	return true;

}

shagun ur code will always give true
try to resolve this by taking some small cases wihch are wrong and still from where they are returning true
If problem exist then reply i will modify ur code

sir could you please modify my code

https://ide.codingblocks.com/#/s/16305
i have modified check this