Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
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
Queries and Logs Search Object
00:00
5 left

Queries and Logs Search Object

MediumSQL · PostgreSQL

Problem

Design a queries search object that reads one line (a string) at a time. If the string has the form "Q: hello world", it is a query whose content is "hello world"; if it has the form "L: hello morning world", it is a log whose content is "hello morning world". Each time you read a query, store its content and assign it a query id. Each time you read a log, return the ids of all queries that appear in that log. A query appears in a log if every word of the query occurs in the log.

Asked in the coding round 1 stage. Follow-ups may require repeated query words to occur at least as many times in the log, or may treat words as simple presence checks.

Output

  1. Use input_messages(line_no, raw_line) as the input.
  2. Return one row per valid log with log_line_no and matching_query_ids.
  3. Assign query IDs by query input order, include logs with no matches as an empty array, and sort by log_line_no.

Schema

input_messages
ColumnTypeDescription
line_noPKINTInput sequence number
raw_lineVARCHAR(255)Raw query or log message
Tablesinput_messages
Interviewer

Your question is Queries and Logs Search Object. 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
Sign up free to run your codeLog inLn 1
Run your query to see results here.