Longest-prefix matching in a network router lookup table
This medium-difficulty coding problem tests your ability to implement a core networking primitive: IP prefix matching. It requires you to build a router class that compares a destination address against a table of prefixes and selects the most specific match, a technique essential to real packet forwarding.
The main challenge is correctly handling wildcard characters in prefix patterns and efficiently finding the longest matching prefix when multiple entries could match the same address. You will need to implement pattern-matching logic and a lookup strategy that is both correct and reasonably performant. Edge cases include addresses with no match, multiple prefixes of different lengths, and the distinction between trailing wildcards and meaningful prefix bits.
- Wildcard pattern matching and prefix length determination
- Iterating and comparing strings character by character
- Handling the
None return case and default routing
- Time complexity of table traversal versus address comparison