Skip to content

Instantly share code, notes, and snippets.

@JamieMagee
Created July 31, 2014 16:41
Show Gist options
  • Save JamieMagee/df88ceba50fc5e0b99d2 to your computer and use it in GitHub Desktop.
Save JamieMagee/df88ceba50fc5e0b99d2 to your computer and use it in GitHub Desktop.
Interview Question
#include <stdio.h>
int main()
{
printf("%i\n", solution("asdfdsa\0"));
printf("%i\n", solution("asddsa\0"));
printf("%i\n", solution("a\0"));
printf("%i\n", solution("ac\0"));
}
int solution(char *S)
{
int counter[26] = {0};
int i = 0;
int odd = 0;
while (*S != '\0')
{
printf("%c", *S);
counter[*S-'a']++;
S++;
}
printf("%c", '\n');
for (i = 0; i < 26; i++)
{
if (counter[i] % 2 != 0 && odd) return 0;
else if (counter[i] % 2 != 0) odd = 1;
}
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment