Mock OA: incident digest
Parse timestamp|user|latency records. Return the busiest user, top-k latencies, and total incident duration in seconds. Break a user-count tie alphabetically.
What you’ll practice
This Level 6 exercise focuses on full ladder synthesis in the Professional curriculum. Solve the challenge prompt above using clear, idiomatic Python and the relevant language or standard-library tools.
Relevant Python reference: Python Standard Library — Professional.
Sample Test Cases
incident_digest(['2026-08-05T10:00:00|userA|100', '2026-08-05T10:05:00|userB|200', '2026-08-05T10:10:00|userA|150'], k=2)digest with busiest user, top 2 latency, durationFurther Reading
Reference Solution
Reveal Reference Solution
def incident_digest(records: list[str], k: int) -> dict: import heapq from collections import Counter from datetime import datetime parsed = [] users = Counter() for record in records: timestamp, user, latency = record.split('|') parsed.append((datetime.fromisoformat(timestamp), user, int(latency))) users[user] += 1 busiest = min(users, key=lambda user: (-users[user], user)) latencies = heapq.nlargest(k, (row[2] for row in parsed)) duration = int((max(row[0] for row in parsed) - min(row[0] for row in parsed)).total_seconds()) return {'busiest_user': busiest, 'top_latencies': latencies, 'duration_seconds': duration}Pro Tips & Keyboard Shortcuts
Open VS Code Color Theme Quick Pick to select from 20 dark and light themes.
Open practice settings drawer to toggle line numbers, indenting, font size & hints.
Expand sidebar menu, focus search bar, and highlight search text instantly.
Instantly highlight and focus code editor from anywhere, restoring cursor right where you left off.
Collapse sidebar and close all popups or settings drawers for clean focus view.