← 返回 twosigma 的题目列表In-Memory SQL-Like Database
类型:qbank
Build an in-memory database that supports creating tables, inserting integer rows, and selecting rows with AND-combined predicates over comparison operators.
Requirements
Input is list[list[str]], where each inner list represents a tokenized query.
Support at least these operations:
create table <tablename> ( <col1> <col2> <col3> )
insert into <table> ( <col_val1> <col_val2> <col_val3> )
select from <tablename> where ( <fieldA> <op1> <valueA> AND <fieldB> <op2> <valueB> )
Constraints and assumptions:
All column values are integers.
Selection operators include >=, =, <=, and similar comparisons.
select only needs to support AND between predicates.
Query format is assumed valid, but field values may be invalid and should be handled deliberately.
Minimum goal is a working end-to-end implementation; polished validation can come after the main path works.
Notes
Keep schema metadata separate from row storage: table_name -> columns, table_name -> rows.
Parse first for operation type, then dispatch. Avoid over-engineering a full SQL parser; the prompt uses constrained token lists.
For select, map column names to indices and evaluate each predicate against the row's integer value.
Candidate experience emphasizes speed: parsing plus AND support can consume the round if the basic path is not implemented first.
Preparation
Write a constrained SQL-token interpreter with create, insert, and select in one sitting.
Drill predicate evaluation for =, <, <=, >, >= and invalid column/value handling.
Prepare a simple table/row data model before the interview so parsing does not dominate.