We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
try and analyze this. I'm giving you the source code.
include
include
include
include
int main() {
int i,j,c=0,x,k;
char a[100];
scanf("%d",&i);
while(i--)
{ c=0; //refreshing the counter
scanf("%s",a);
x=strlen(a); //length of string
for(j=0;j!=x-1;j++) //no need to traverse till end //but end-1
{
if(a[j] ==a[j+1]) //calc. those which are same
{ c++;
}
}
printf("%d\n",c);
}
return 0;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Alternating Characters
You are viewing a single comment's thread. Return to all comments →
yeah . Mine is O(n).
try and analyze this. I'm giving you the source code.
include
include
include
include
int main() { int i,j,c=0,x,k; char a[100]; scanf("%d",&i);
}