by School-Cotton · 4y ago · 0 comments
But if you’re willing to assume that none of the ages are more than some reasonable constant bound, like no employees over the age of 65535 or something, then there’s a fun guaranteed O(n) algorithm closely related to counting sort.
(Note, however, that counting occurrences is in principle at least O(log n) space and, without a bit of cleverness, likely O(n log n) time—your integers need to be O(log n) wide to count that big!)
There's the right answer right there.
I'll add: let the AI handle the details.
def getMedianAge(person_list):
# Let copilot fill in rest