Parse retention duration

Write codeEasy15 min

Your task

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.

Examples

retention_window_seconds(policies: list[str]) -> list[int]
Example 1
Inputretention_window_seconds(["90m", "1h30m", "2d", "45"])
Output[5400, 5400, 172800, -1]
Example 2
Inputretention_window_seconds(["7d", "12h", "1h30m15s", "0s"])
Output[604800, 43200, 5415, 0]