FastPrepParse and Query Server Logs
Problems/Parse and Query Server Logs

Parse and Query Server Logs

Kikoff logoKikoff● HardNEW GRADPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Kikoff new grad phone screen. The report does not give the exact log format. It also leaves out what to do with bad lines, the edge cases of the queries, and how to write the result. We filled those in. Our version is about 90% the same as the reported question.

You are given server-log lines, and some of them may be broken. Parse the lines, run a query on the valid ones, and return every valid log that matches.

A line is valid when it has exactly four fields separated by tabs:

  1. a timestamp written exactly as YYYY-MM-DDTHH:MM:SSZ,
  2. a level: one of DEBUG, INFO, WARN, or ERROR,
  3. a service name that is not empty and uses only ASCII letters, digits, underscores, or hyphens, and
  4. a message that is not empty and has no tab in it.

For the timestamp, each number part must have exactly as many digits as the pattern shows. The year must be from 1970 through 9999, the month from 01 through 12, and the day from 01 through 31. The hour must be from 00 through 23, and the minutes and seconds from 00 through 59. These are the only timestamp checks. Throw away every line that breaks any rule above.

If the message contains user_id=value as a standalone token, take the value from the first such token. The value may use only ASCII letters, digits, underscores, or hyphens. Otherwise, the user identifier is empty.

The query may start with any of these operators, each used at most once: level:value, service:value, userid:value, start:YYYY-MM-DD, and end:YYYY-MM-DD. Operator names and level values ignore case. Service, user, and message matches are case-sensitive. The start date is included, and the end date is not. Any text after the leading operators is a case-sensitive filter: the message must contain that text.

Keep the matching logs in input order. Return a string array. The first element is the number of matches, written in decimal. Each remaining element is one log in the form timestamp TAB level TAB service TAB message TAB userId. Write the level in uppercase, and leave the last field empty when there is no user identifier.

Function

parseAndQueryServerLogs(logs: String[], query: String) → String[]

Examples

Example 1

logs = ["2026-08-07T09:30:00Z\tERROR\tapi\trequest failed user_id=u7","bad line","2026-08-07T10:00:00Z\tINFO\tapi\trequest recovered","2026-08-08T01:00:00Z\tERROR\tworker\tjob failed user_id=u8"]query = "level:error service:api start:2026-08-07 failed"return = ["1","2026-08-07T09:30:00Z\tERROR\tapi\trequest failed user_id=u7\tu7"]

The line bad line is not a valid log, so it is thrown away before the query runs. The first line is an ERROR from api on the start date, and its message contains failed, so it matches. The INFO line fails the level filter, and the worker line fails the service filter. So the answer holds a count of one, then the first log with u7 as its user identifier.

Constraints

  • 1 <= logs.length <= 200000
  • Each line and the query contain at most 2000 characters.
  • Service names and user identifiers contain at most 64 characters.
  • The query follows the operator rules above, and its tokens are separated by single ASCII spaces.

More Kikoff Phone Screen questions

  • Nested Substitutions with Cycle DetectionPHONE SCREEN · Seen Nov 2026
  • Realized Gains from a Real-Estate Transaction StreamPHONE SCREEN · Seen Nov 2026
  • JSON Identity VerificationPHONE SCREEN · Seen Jul 2026

Similar questions at other companies

  • Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
  • Business Account KYC Verification — Parts 1–5Stripe · PHONE SCREENStripe interview questions
  • CSV Row SerializerMercor · PHONE SCREENMercor interview questions
  • Host Log ParserVerkada · PHONE SCREENVerkada interview questions
  • Length-Prefixed String CodecSnowflake · PHONE SCREENSnowflake interview questions
  • Restricted Decimal Number ValidatorLinkedIn · PHONE SCREENLinkedIn interview questions
  • Machine Message RouterOpenAI · PHONE SCREENOpenAI interview questions
  • HTTP Status Log SummaryApple · PHONE SCREENApple interview questions
  • Alert After Repeated Column Threshold BreachesMeta · PHONE SCREENMeta interview questions
  • Serialize a Nested Dictionary as JSONGoogle · PHONE SCREENGoogle interview questions
All Kikoff interview questionsSee Kikoff hiring insights
Saved
class Solution {
    public String[] parseAndQueryServerLogs(String[] logs, String query) {
      // write your code here
    }

}
Checking account…