Daily iOS
CS fundamentals and algorithms

Parsing corrupted logs

Your app writes a network log file. Each line has the format userID(4 digits) pageName startTime(hh:mm:ss) endTime(hh:mm:ss), but some lines are corrupted. How would you design a function that keeps only valid lines and finds the 2 pages that loaded slowest? How do you handle the broken lines?

How would an interviewer hear this answer? You'll see whether they'd move on, dig in, or say no, and which sentences would trip you up. Your score doesn't change.
See the short answer

Split each line into tokens, validate field count, digit count, and time ranges, and skip on failure; convert times to integer seconds and take the difference, correcting for crossing midnight. Track the top 2 in a single pass with two variables (or a min heap of size 2) instead of sorting.

Share a question