Parse and Store Log Records
Problem statement
Parse the log lines and return their stored records.
For this exercise, each valid line has the form timestamp|level|message with exactly two pipe separators. The timestamp is a nonnegative decimal integer written without leading zeros except for 0. The level is INFO, WARN, or ERROR. The message may be empty and contains no pipe.
Return each record as three strings [timestamp, level, message], sorted by increasing numeric timestamp. Keep equal-time records in their original order. Preserve every duplicate record and the exact message text, including spaces.
Function
parseAndStoreLogs(lines: String[]) → String[][]Examples
Example 1
lines = ["12|INFO|started","3|ERROR|disk full","12|WARN|retry"]return = [["3","ERROR","disk full"],["12","INFO","started"],["12","WARN","retry"]]Records sort by numeric timestamp. The two time-12 records retain their original order.
Example 2
lines = ["0|INFO|"]return = [["0","INFO",""]]An empty message is valid and remains the third field.
Example 3
lines = []return = []No input records produces an empty stored collection.
Constraints
- For this exercise, assume
0 <= lines.length <= 100. - All lines satisfy the stated input format.
- Timestamps are between
0and10^9. - Each message contains at most
100printable ASCII characters and no pipe.