cybersecurity · intermediate · ~15 min · safe pentest lab
Count unique values.
Count how many distinct ports a source touched — a burst across many distinct ports is the port-scan signature.
Implement int distinct_ports(const int *ports, int n) that returns the number of distinct port numbers in the array.
ports: an array of n port numbers the grader passes (may contain duplicates).n: the array length.Returns int: the count of distinct values.
distinct_ports({22, 80, 22, 443, 80}, 5) -> 3 (22, 80, 443)
An int array ports of length n.
An int: the number of distinct port values.
Duplicates count once.
int distinct_ports(const int *ports, int n) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.