Skip to content

Instantly share code, notes, and snippets.

@saccharineboi
Created June 6, 2025 12:33
Show Gist options
  • Save saccharineboi/77c3dd1f5ea19abde8f12b7112857134 to your computer and use it in GitHub Desktop.
Save saccharineboi/77c3dd1f5ea19abde8f12b7112857134 to your computer and use it in GitHub Desktop.
Exercise 1.4 of cracking coding interview
#include <stdio.h>
#include <stdbool.h>
#include <ctype.h>
#define EXT_ASCII_LEN 256
static bool is_perm_of_pal(const char* restrict s)
{
if (!s) {
return false;
}
int counts[EXT_ASCII_LEN] = {};
for (; *s; ++s) {
if (isalnum(*s)) {
++counts[tolower(*s)];
}
}
int oddCnt = 0;
for (int i = 0; i < EXT_ASCII_LEN; ++i) {
if (counts[i] > 0 && counts[i] & 1) {
++oddCnt;
}
}
return oddCnt < 2;
}
int main(int argc, char** argv)
{
if (argc < 2) {
printf("usage: %s <string>\n", argv[0]);
return 0;
}
printf("%d\n", is_perm_of_pal(argv[1]));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment