← Reddit Interview InsightsSoftware Engineer
My first instinct was to just iterate through and track each admin's latest timestamp in a map, then sort at the end.
Parse each log entry to extract the admin name, action, executor, and timestamp. Filter for 'add' actions, then use a hash map to track the latest timestamp for each admin. Finally, sort the admins by their latest timestamp and return the ordered list.
Pro tip: Clarify the timestamp format and whether ties should be broken alphabetically. Also, consider if the log is huge—mention streaming or external sorting if memory is a concern.
Ask about timestamp format, tie-breaking rules, and expected input size. Confirm that only 'add' actions are considered and that the output should be sorted by most recent timestamp.
Split the log string into entries (e.g., by newline) and parse each entry into its components: admin, action, executor, timestamp. Handle potential edge cases like extra spaces or missing fields.
Iterate through the parsed entries, and for each 'add' action, update a hash map with the admin as key and the maximum timestamp seen so far as value.
Extract the admins from the hash map, sort them by their latest timestamp in descending order (most recent first), and return the sorted list. If timestamps are equal, apply the tie-breaking rule (e.g., alphabetical).
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.