Out of order log lines
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.
Implement
count_out_of_order(lines: list[str]) → intExamples
in
[["2026-07-01T10:00:05 INFO a","2026-07-01T10:00:02 INFO b","2026-07-01T10:00:09 INFO c"]]out1What a strong answer looks like
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.
0:00 of about 10 min
solution.py
InputExpectedGot
[["2026-07-01T10:00:05 INFO a","2026-07-01T10:00:02 INFO b","2026-07-01T10:00:09 INFO c"]]1not run yetsample