cybersecurity · beginner · ~12 min · safe pentest lab
Linear-time deduplication against a fixed-capacity seen-set in pure C.
Implement:
int count_unique_domains(const char *list);
Walk the \n-separated input. Ignore empty lines. Compare lines
case-insensitively. Return the number of unique entries, or 0 if
list == NULL. Cap at 256 distinct entries — if more, return -1.
"www\napi\nwww\nmail\n" → 3"www\nWWW\n" → 1 (case-insensitive)"\n\n\n" → 0\n, lowercase each token into a stack
buffer, then linear-scan a seen[256][64] table.\n. Stop at \0.Recon pipelines start by deduplicating wordlists. Writing the deduper in C teaches the linear-scan + small-table pattern.
A NUL-terminated string of \n-separated subdomain labels.
Unique count (0..256), or -1 if the cap is exceeded.
Cap distinct entries at 256. Per-entry label <= 63 chars.
int count_unique_domains(const char *list) {
/* TODO */
(void)list;
return 0;
}
Forgetting trailing-NL-less input. Allowing empty lines through. Reading past NUL.
Cap at exactly 256. Case variation. Single line without newline.
O(input_len * unique_count). Bounded by 256 unique × 64 bytes.
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.