PracticeLevel 6: ProfessionalEx 150. Mock OA: incident digest
0/150 Solved(0%)
Level 6Exercise #150

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.

Mock Assessment: 35-minute timed interview problem. Reason about edge cases before submitting.

Sample Test Cases

Example #1
Input: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)
Output:digest with busiest user, top 2 latency, duration

Further 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
Color Theme
Ctrl + K then T

Open VS Code Color Theme Quick Pick to select from 20 dark and light themes.

Editor SettingsCtrl + K

Open practice settings drawer to toggle line numbers, indenting, font size & hints.

Search MenuCtrl + /

Expand sidebar menu, focus search bar, and highlight search text instantly.

Focus Code Editor
Esc or Ctrl + `

Instantly highlight and focus code editor from anywhere, restoring cursor right where you left off.

Normal ViewEsc

Collapse sidebar and close all popups or settings drawers for clean focus view.

solution.py· Python 3.11 WASM