</>OfferRetriever
DashboardDiscuss
NEW

Spring Hire Sale

Limited Time Deal: Unlock all premium questions for over 30% off

$10.42$7.08

08

:

04

:

53

:

47

Get this deal
Back to Dashboard

Longest Prefix Router

Medium

You are building a network packet forwarder. Given a routing table and a list of incoming packet source addresses, determine the correct gateway for each packet using longest prefix match (LPM).

The routing table is a list of [prefixCIDR, gateway] pairs. For each packet IP address, find the route whose prefix is the longest (most specific) match. If multiple routes match, the one with the longest prefix length wins. If no route matches, return "" for that packet. ...