Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Nested Record Query Index

HardPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Nested Record Query Index. Start with the requirements on the right.

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.

Problem

Given a list of records where each record is a nested dictionary, implement a function that preprocesses the records and answers equality-based search queries efficiently. Each query is a dictionary mapping dot-separated field paths (such as "user.name" or "meta.region") to required values. Return the list of record IDs that satisfy all query conditions.

Constraints

  • 1 <= len(records) <= 10^4
  • Each record contains a unique integer id
  • Nested depth is at most 5
  • 1 <= len(queries) <= 10^4
  • Each query contains 1 to 10 equality filters
  • Queried field values are strings, integers, or booleans

Function Signature

def optimize_queries(records, queries):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output