FastPrepStructured Log Stream with Queries
Problems/Structured Log Stream with Queries

Structured Log Stream with Queries

OpenAI logoOpenAI● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A report from September 2026 says the 60-minute phone screen was about reading a stream of log records and answering questions about them quickly, with each follow-up adding to the last.

The report does not give the entry format, the query types or the follow-ups. Here each entry has a time and key=value fields. Times never go down, and a query only sees earlier entries. COUNT counts entries in an inclusive time range, with an optional exact field match. TOP lists the most common values of a field, with ties in text order and NONE when nothing matches. The examples are our own.

Our version is about 45% the same as the reported question.

A service writes structured log entries one after another. Between the entries, someone asks questions about the entries seen so far. You get the whole stream as a list of lines lines. Handle the lines in order and return the answer to every query, in order.

Each line is one of three kinds:

  • "LOG t key1=value1 key2=value2 ..." adds an entry with time t and one or more fields. A field is a key and a value joined by '=', and the fields may come in any order. This line has no output.
  • "COUNT a b" asks how many entries so far have a time from a to b, both ends included. "COUNT a b key=value" counts only the entries in that range that have the field key with exactly this value. The answer is the count as a decimal string.
  • "TOP k key a b" looks at the entries so far with a time from a to b that have the field key. It returns the k values of key that appear most often, written as "value:count" pieces joined by commas.

In a TOP answer, more frequent values come first. Values with the same count are compared as text, one character at a time by character code, and the smaller one comes first, so "10" comes before "9". If fewer than k values exist, list all of them. If no entry in the range has the key, the answer is "NONE".

A query only sees entries from earlier lines. An entry without the asked key never matches a filter and is skipped by TOP.

Function

processLogStream(lines: String[]) → String[]

Examples

Example 1

lines = ["LOG 3 svc=auth level=error","LOG 5 svc=pay level=info","LOG 5 svc=auth level=info user=u7","COUNT 4 5","COUNT 0 10 svc=auth","LOG 9 svc=auth level=error","COUNT 3 9 level=error","TOP 2 svc 0 9"]return = ["2","2","2","auth:3,pay:1"]

COUNT 4 5 counts entries with time from 4 to 5: the two entries at time 5, so "2".

COUNT 0 10 svc=auth runs before the entry at time 9 arrives, so only the entries at times 3 and 5 with svc=auth count: "2".

After the entry at time 9 arrives, COUNT 3 9 level=error finds the entries at times 3 and 9: "2". TOP 2 svc 0 9 sees auth 3 times and pay once: "auth:3,pay:1".

Example 2

lines = ["COUNT 0 100","LOG 10 user=ann","LOG 20 user=bob code=404","TOP 3 code 0 100","TOP 1 user 15 15","COUNT 10 20 code=4"]return = ["0","404:1","NONE","0"]

The first query comes before any entry, so the count is "0".

TOP 3 code 0 100: only the entry at time 20 has a code field, so the answer has one value, "404:1". TOP 1 user 15 15 looks only at time 15, where there is no entry, so the answer is "NONE".

COUNT 10 20 code=4 needs code to equal 4 exactly. 404 is a different value, so the count is "0".

Example 3

lines = ["LOG 1 host=b","LOG 2 host=a","LOG 2 host=c","LOG 4 host=a","LOG 6 host=c","TOP 3 host 2 6","TOP 1 host 1 2"]return = ["a:2,c:2","a:1"]

TOP 3 host 2 6 looks at times 2 to 6: a appears twice, c twice and nothing else. a and c tie at 2, so the smaller value comes first: "a:2,c:2".

TOP 1 host 1 2 sees b, a and c once each. All three tie, so only the smallest value, a, is kept: "a:1".

Constraints

  • 1 <= lines.length <= 3000
  • 1 <= lines[i].length <= 60
  • Every line is one of the three kinds above, with tokens separated by single spaces. Every time, a and b is an integer from 0 to 10^9 written without leading zeros, and a <= b in every query.
  • Entry times never decrease from one LOG line to the next.
  • An entry has 1 to 4 fields with distinct keys. A key has 1 to 8 lowercase English letters, and a value has 1 to 8 lowercase English letters or digits.
  • In every TOP query, 1 <= k <= 5, and at most 100 lines are TOP queries.

More OpenAI Phone Screen questions

  • Secret Number Search with One-Call-Delayed FeedbackPHONE SCREEN · Seen Nov 2026
  • Determine the Winner of Three-Card HandsPHONE SCREEN · Seen Nov 2026
  • Grid Infection with Recovery After D DaysPHONE SCREEN · Seen Nov 2026
  • Sparse Plant Infection SimulationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Light Source Hits: Sample, Compare, and FitPHONE SCREEN · Seen Nov 2026
  • Rectangle Point Coverage CountsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Adaptive Calibration ErrorPHONE SCREEN · Seen Nov 2026
  • Elevator Scheduling SimulationPHONE SCREEN · Seen Nov 2026
  • Evaluate Noisy AnnotatorsPHONE SCREEN · Seen Oct 2026
  • Network Endpoint or Cycle BoundaryOA · PHONE SCREEN · Seen Oct 2026

Similar questions at other companies

  • Interview Slot BookingTrueFoundry · PHONE SCREEN
  • Transaction Event StoreCapital One · ONSITE INTERVIEWCapital One interview questions
  • Order Manager with Partial Cancellations and Indexed QueriesStripe · ONSITE INTERVIEWStripe interview questions
  • In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
  • Top K Pins with Insert and QueryPinterest · PHONE SCREENPinterest interview questions
  • Snapshot Map with Sparse Version HistorySnorkel AI · PHONE SCREEN
  • Worst-Performing Ads by CTR in a Campaign TreeUber · PHONE SCREENUber interview questions
  • Camel CardsRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
  • Maintain a Consistent-Hashing RingApple · PHONE SCREENApple interview questions
  • Time-Based Key-Value StoreOracle · PHONE SCREEN · ONSITE INTERVIEWOracle interview questions
All OpenAI interview questionsSee OpenAI hiring insights
Saved
class Solution {
    public String[] processLogStream(String[] lines) {
        // Write your code here.
    }
}
Checking account…