Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
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

Whenever you're ready, walk me through your approach or go straight to the code. The requirements and the one table are in the Question tab.

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