</>OfferRetriever
DashboardDiscuss
NEW

July 4th Sale

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

$10.42$6.25

10

:

09

:

25

:

19

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. ...