Given a multi-level boolean query find the level of a given term. E.g. query = A AND (B OR C), term = B -> 1; term = A -> 0; term = D -> -1; query = B AND ((A AND B)), term = B -> 1 (consider deepest level); query = ((A)), term = A -> 0. Operators are AND/OR; operands can be strings with spaces.
Asked in the DSA round stage. Write a SQL query using the provided tables.
query_id, term, and term_level.-1 when the term is absent. Order by query_id.| Column | Type | Description |
|---|---|---|
| query_idPK | INT | Identifier for the boolean query |
| expression | TEXT | Boolean expression containing operands, AND, OR, and parentheses |
| Column | Type | Description |
|---|---|---|
| request_idPK | INT | Identifier for the requested term row |
| query_id | INT | Boolean query being searched |
| term | TEXT | Operand whose deepest level must be returned |