Cache expiry seconds
A shared CDN edge has just stored a response and must decide how many seconds it may serve that copy before asking the origin again. The response's cache directives arrive as separate strings, each either a bare name such as public or a name and value joined by an equals sign such as max-age=600. A directive may carry surrounding spaces and any letter case. Apply these rules in this order and return the number of seconds. Return -1 when no-store or private appears anywhere, since a shared cache may not keep the response at all. Return 0 when no-cache appears, since every hit must be revalidated. Otherwise return the value of s-maxage, then the value of max-age, using the first occurrence of a repeated name and skipping any value that is not a run of digits. Otherwise return default_ttl. Ignore all other directives.
edge_cache_seconds(directives: list[str], default_ttl: int) → int[["public","max-age=600"],60]out600[["max-age=600","s-maxage=120"],60]out120[["no-store"],60]out-1State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
[["public","max-age=600"],60]600not run yetsample[["max-age=600","s-maxage=120"],60]120not run yetsample[["no-store"],60]-1not run yetsample