FastPrepParse and Order Structured Logs
Problems/Parse and Order Structured Logs

Parse and Order Structured Logs

Coinbase logoCoinbase● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Coinbase onsite interview. The report keeps only a log-parsing coding task. It leaves out the row format, the rules for a valid row, the fields to return, the ordering, and the limits. Our version fills in those details so the answer is always the same.

You are given an array of log lines. Keep only the valid lines. A valid line has exactly four fields, separated by the pipe character:

timestamp|level|service|message

  • timestamp is a whole number written with digits only. It is either 0 or starts with a digit from 1 through 9, so it has no leading zeros. Its value is at most 1000000000.
  • level is exactly INFO, WARN, or ERROR.
  • service is not empty and contains only English letters, digits, underscores, or hyphens.
  • message is not empty. No field contains the pipe character.

Skip every invalid line. For each valid line, return one row [timestamp, level, service, message]. Sort the rows by timestamp as a number, smallest first. When two timestamps are equal, keep the rows in the order they had in the input.

Function

parseLogs(logs: String[]) → String[][]

Examples

Example 1

logs = ["10|INFO|api|started","2|ERROR|db|down","10|WARN|api|slow"]return = [["2","ERROR","db","down"],["10","INFO","api","started"],["10","WARN","api","slow"]]

Sorted by timestamp, the row with 2 comes first. The two rows with timestamp 10 keep their input order, so INFO comes before WARN.

Example 2

logs = ["01|INFO|api|leading zero","0|INFO|boot_service|ready now","7|DEBUG|api|trace","8|WARN|api|","9|ERROR|db|disk full"]return = [["0","INFO","boot_service","ready now"],["9","ERROR","db","disk full"]]

Three lines are skipped. The first has a timestamp with a leading zero. The third has a level, DEBUG, that is not allowed. The fourth has an empty message. The other two lines are valid, and they are already sorted by timestamp.

Constraints

  • 0 <= logs.length <= 100000.
  • 1 <= logs[i].length <= 500.
  • Every input character is printable ASCII.

More Coinbase interview questions

  • Scheduled Payments with Account AliasesONSITE INTERVIEW · Seen Oct 2026
  • Dynamic Fixed-K Score LeaderboardONSITE INTERVIEW · Seen Aug 2026
  • Minimum Days for Fixed-Order Tasks with CooldownONSITE INTERVIEW · Seen Aug 2026
  • Sliding-Window Averages as Reduced FractionsONSITE INTERVIEW · Seen Aug 2026
  • Select Transactions with Child-Pays-for-Parent PackagesPHONE SCREEN · Seen Oct 2026
  • Task Management SystemOA · Seen Sep 2026
  • Cloud Compute Credits SystemOA · Seen Aug 2026
  • Banking System with Historical SnapshotsOA · Seen Aug 2026
  • Find the Length of the Longest Common PrefixOA · Seen Oct 2024
  • Lexicographically Smallest Topological OrderPHONE SCREEN · Seen Apr 2022

Similar questions at other companies

  • Rank Word-Translation Hints from Sentence TranslationsDuolingo · PHONE SCREEN · ONSITE INTERVIEWDuolingo interview questions
  • Response Time Stats by URL PatternGusto · ONSITE INTERVIEWGusto interview questions
  • Deep Merge with a Conflict ResolverAutodesk · ONSITE INTERVIEWAutodesk interview questions
  • Insert an Employee into an Organization HierarchyWaymo · PHONE SCREENWaymo interview questions
  • Group AnagramsAmazon Web Services · ONSITE INTERVIEWAmazon Web Services interview questions
  • Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
  • Longest Consecutive Login StreakAmazon · ONSITE INTERVIEW
  • Keyboard Autocomplete SuggestionsLyft · ONSITE INTERVIEWLyft interview questions
  • Flatten a Mixed JSON ListNike, Inc. · ONSITE INTERVIEWNike, Inc. interview questions
  • Transform Dotted Keys into a Nested MapProofpoint · ONSITE INTERVIEW

Coinbase interview experiences

  • Coinbase SWE Phone Screen and Final Loop: 1 Experience
All Coinbase interview questionsSee Coinbase hiring insights
Saved
class Solution {
    public String[][] parseLogs(String[] logs) {
        // write your code here
    }
}
Checking account…