Skip to content

Instantly share code, notes, and snippets.

@roxsula
Created January 28, 2019 21:42
Show Gist options
  • Save roxsula/855e774de1a8b06d9554fbc624a08cc2 to your computer and use it in GitHub Desktop.
Save roxsula/855e774de1a8b06d9554fbc624a08cc2 to your computer and use it in GitHub Desktop.
Alternating Characters HackerRank - Refreshing C knowledge - return an integer representing the minimum number of deletions to make the alternating string.
int alternatingCharacters(char* s) {
int c = 0;
char* AB = "AB";
char* BA = "BA";
char *ptr1 = strstr(s, AB);
char *ptr2 = strstr(s, AB);
if (ptr1 != NULL || ptr2 != NULL)
{
for (int i = 0; i < strlen(s) - 1; i++) {
if (s[i] == s[i + 1]) {
c += 1;
}
}
return c;
}
else
{
return strlen(s) - 1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment