Indexed Person Record Queries
Problem statement
You are given unique field names in fields and an immutable table of person records. Let C = fields.length. The table is stored row by row in cells: record r has value cells[r * C + c] for field fields[c]. Records are identified by their zero-based input row indices.
Queries are stored in queryTerms and queryOffsets. Query q is the slice from queryOffsets[q] inclusive to queryOffsets[q + 1] exclusive. Each slice alternates [field, value, field, value, ...]. A record matches only when it satisfies every listed equality. Compare strings exactly and case-sensitively; wildcard characters have no special meaning.
Examples
Example 1
fields = ["id","name","team"]cells = ["u1","Ada","A","u2","Bob","B","u3","Ada","B","u4","Chen","A"]queryTerms = ["name","Ada","team","B","name","Ada","team","C"]queryOffsets = [0,2,6,8]return = [[0,2],[2],[]]Records 0 and 2 have name Ada. Only record 2 also has team B. No record has team C.
Unlock this recently reported problem
FastPrep Pro gives you full access to interview problems reported within the last week.
- Full problem statement and constraints
- 2 more worked examples, explained
- Guided hints and editorial
- Run your code on real test cases
$99 billed yearly — or $19 month-to-month. Cancel anytime.