Parse retention duration
A log platform stores each stream's retention as a compact duration string. A policy is one or more parts run together with nothing between them. Each part is one or more decimal digits followed by exactly one unit letter: d for days, h for hours, m for minutes, s for seconds. Units must appear in strictly descending size, d before h before m before s, so a unit shows up at most once and "30m2h" is refused. A day is 86400 seconds, an hour is 3600 and a minute is 60. Add the parts up. Anything outside that shape reports -1: an empty policy, digits with no unit after them, a unit with no digits before it, an uppercase letter, a space, a repeated unit, units out of order. Leading zeros are fine and no number runs past six digits. Return one integer per policy, in the order given.
retention_window_seconds(policies: list[str]) → list[int][["90m","1h30m","2d","45"]]out[5400,5400,172800,-1][["7d","12h","1h30m15s","0s"]]out[604800,43200,5415,0]State 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.
[["90m","1h30m","2d","45"]][5400,5400,172800,-1]not run yetsample[["7d","12h","1h30m15s","0s"]][604800,43200,5415,0]not run yetsample