Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Live-tail Query-Log Matching
00:00
5 left

Live-tail Query-Log Matching

MediumSQL · PostgreSQL

Problem

Given a live-tail stream of lines where "Q: " registers a query and "L: " is a log line, acknowledge each query with an incrementing ID and, for every log line, output the IDs of all queries whose words all appear in that log.

Asked in the coding round 2 stage. This was a 60-minute coding round, and upper/lower case handling is part of the problem.

The input table is stream_events(event_id, raw_line). Treat matching as case-insensitive and ignore punctuation when identifying words.

Output

  1. One row per input query or log event, ordered by event_id
  2. Columns: event_id, response_type, query_id, matching_query_ids
  3. For query events, return the assigned query_id; for log events, return all matching IDs in ascending order, or an empty array when none match

Schema

stream_events
ColumnTypeDescription
event_idPKINTUnique position of the line in the live-tail stream
raw_lineTEXTRaw stream line beginning with Q: or L:
Tablesstream_events
Interviewer

Your question is Live-tail Query-Log Matching. Start with the requirements and the one table in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePostgreSQL
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.