Out of order log lines

Write codeEasy10 min

Your task

A log collector merges lines from many app instances, and clock skew sometimes makes timestamps go backwards. Each line starts with a sortable timestamp string like "2026-07-01T10:00:05" followed by a space and the rest of the entry. Comparing these timestamps as plain strings gives chronological order. Return how many lines arrive strictly earlier than the line directly before them, that is, count positions i > 0 where timestamp[i] < timestamp[i-1]. Equal neighboring timestamps are fine and count as in order.

Examples

count_out_of_order(lines: list[str]) -> int
Example 1
Inputcount_out_of_order(["2026-07-01T10:00:05 INFO a", "2026-07-01T10:00:02 INFO b", "2026-07-01T10:00:09 INFO c"])
Output1