Average Process Time from CSV
Updated
Problem statement
You are given rows, a list of CSV rows. Each row has the form id,start,end, where start and end are integer timestamps and end >= start. The process duration of a row is end - start.
Group the rows by id and find each ID's average process duration. The input guarantees every average is an integer.
Return one pair [id, average] per ID, with the average written as a string. Sort the pairs lexicographically by ID.
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 two rows with durations 10 and 20, so its average is 15. ID b has one row, so its average is that row's duration. Sorted by ID, a comes before b, which gives the output shown.
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.
More Abnormal Security Phone Screen questions
Similar questions at other companies
- Shared Courses for Every Pair of StudentsCrunchyroll · PHONE SCREENCrunchyroll interview questions
- Portfolio Valuation, Part 1Stripe · PHONE SCREENStripe interview questions
- Summarize Server Healthcheck LogsNVIDIA · PHONE SCREENNVIDIA interview questions
- Convert an Entry List to a MapEPAM · PHONE SCREENEPAM interview questions
- Best Anagram MatchGoogle · PHONE SCREENGoogle interview questions
- Word Frequency in a Large TextRobinhood · PHONE SCREENRobinhood interview questions
- Remove Later Anagrams From a ListBloomberg LP · PHONE SCREENBloomberg LP interview questions
- Employees With Shared InterestsPalantir · PHONE SCREENPalantir interview questions
- Rank Words by FrequencyDatadog · PHONE SCREENDatadog interview questions
- Sort Letters by FrequencyScale AI · PHONE SCREENScale AI interview questions