Code Room
CodingEasycod-g1313
Subject Log processingLevel Entry–Mid~10 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

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]) → int
Examples
in[["2026-07-01T10:00:05 INFO a","2026-07-01T10:00:02 INFO b","2026-07-01T10:00:09 INFO c"]]out1
What 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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.