Average Process Time from CSV
Reported by candidates from Abnormal Security's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The Abnormal Security OA, reported in April 2024, looks like a warmup. Parse CSV rows, group by ID, average the durations, sort. It's a hash-table problem with a thin layer of string handling, and it's the kind of question where small slips cost you the whole run. If you've got an invite in your inbox, expect something this plain with a couple of traps in the details. StealthCoder sits invisibly on your screen as a safety net if you blank mid-assessment, but this one is very doable if you read the constraints carefully before typing.
The problem
Each CSV row has the form id,start,end, where start and end are integer timestamps and end >= start. Group rows by id and return each ID's average process duration end - start. Return rows [id, average] sorted lexicographically by ID. The input guarantees every average is an integer. Function averageProcessTimes(rows: String[]) → String[][] Examples Example 1 rows = ["a,10,20","b,0,4","a,30,50"] return = [["a","15"],["b","4"]] ID a has durations 10 and 20, whose average is 15. Constraints 1 <= rows.length <= 100000. IDs are nonempty ASCII strings without commas. 0 <= start <= end <= 10^9. Each per-ID duration sum is divisible by its row count.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is a hash map from ID to a running pair: total duration and row count. Split each row on commas, parse start and end as integers, add end minus start to the sum, bump the count. Then sort the keys and emit [id, sum/count] as strings. The edge case that breaks a naive solution is the sort. Lexicographic means plain string order, so "a10" comes before "a2". Don't sort numerically or by insertion order. The other pitfall is the return type: the average must be a string, not an int. Sums can reach 10^5 times 10^9, so use 64-bit integers in Java or C++. The problem guarantees divisibility, so integer division is safe. Total cost is O(n + k log k). If you freeze on output formatting or the overflow, StealthCoder can hand you a clean reference during the live OA.
StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.
You can drill Average Process Time from CSV cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. If you're reading this with an OA window open, you're who this was built for.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Abnormal Security's OA.
Abnormal Security reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Average Process Time from CSV FAQ
How hard is the Abnormal Security average process time question?+
Easy. It's a group-by with a sort. The difficulty comes from careless details: string output, lexicographic ordering, and integer overflow on large sums. If you handle those three, you're done in well under twenty minutes.
What's the core trick?+
Use a hash map from ID to total duration and count. One pass over the rows, then sort the keys once. Don't store every duration in a list, since you only need the sum and the count to get the average.
Do I need to worry about integer overflow?+
Yes, in fixed-width languages. Each duration can be up to 10^9 and there can be 100000 rows, so a single ID's sum can hit 10^14. Use a 64-bit type. Python handles it automatically.
How should I sort the IDs?+
Plain string comparison on the ID, which is what lexicographic means here. Don't try to parse numbers out of IDs. With this ordering, "a10" sorts before "a2", and that's the expected result.
How do I prepare for this in 48 hours?+
Practice parsing delimited strings and grouping with a hash map in your language of choice. Write the solution once from scratch, check your output types, and test an ID with a single row plus IDs that sort oddly.