Dsa
Trie
Easy
Smart Home Command Router
A smart home hub receives voice commands. You must route these commands to handlers based on the LONGEST matching prefix registered. If a command starts with 'light.on', it goes to the LightHandler. If it starts with 'light.on.kitchen', it goes to the KitchenHandler. If multiple handlers match, the most specific (longest) one wins. If no prefix matches, print 'UNKNOWN'.
Example:
Input:
2
light.on LightHandler
light.on.kitchen KitchenHandler
2
light.on.bedroom
light.on.kitchen.sink
Output:
LightHandler
KitchenHandler
Key concepts
trieprefix-matchingparsing
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now