Given a rooted tree whose edges are labelled with lowercase letters, answer Q queries: does the path from the root to the given node form a palindrome? Target O(N+Q). Asked in the DSA round stage. The interviewer expected an O(N+Q) solution. Use the tree_nodes and palindrome_queries tables.
query_id, node_id, and is_palindrome.query_id ascending.| Column | Type | Description |
|---|---|---|
| node_idPK | INT | Unique identifier of the tree node |
| parent_id | INT | Parent node identifier, or NULL for the root |
| edge_label | VARCHAR(1) | Lowercase label on the edge from the parent, or NULL for the root |
| Column | Type | Description |
|---|---|---|
| query_idPK | INT | Unique identifier of the query |
| node_id | INT | Node whose root path must be checked |