Begged Interviewer to let me drop off the Interview | Forward Networks | 6YOE
Anonymous User
604
Mar 26, 2026

2 Rounds

Round 1

Onilne Assesment

Round 2

A network device maintains Policy Based Routing (PBR) entries. Each entry contains an IP subnet in CIDR notation and a corresponding next-hop IP address.

When a packet with a destination IP arrives, the device must determine the next-hop based on the Longest Prefix Match rule.

If multiple subnets match the destination IP, the subnet with the largest prefix length must be selected.
If no subnet matches, the default route (0.0.0.0/0) should be used.

You are given:

A list of PBR entries represented by a class PrefixEntry, where:
ipSubnet is a subnet in CIDR format (e.g., "168.19.100.0/24")
nextHop is the next-hop IP address.
A list of IPv4 addresses.

Write a function:

public static Map<String, String> findNextHops(
List prefixEntries,
List ipAddresses)

The function should return a mapping of each IP address to the next-hop IP address determined using the longest prefix match.

Example

Prefix entries:

168.19.100.34/32 → 1.1.1.1
168.19.100.0/25 → 1.1.1.2
168.19.100.0/24 → 1.1.1.3
168.0.0.0/8 → 1.1.1.4
0.0.0.0/0 → 1.1.1.5

IP addresses:

168.19.100.34
168.19.100.198
169.0.0.0

Expected output:

168.19.100.34 → 1.1.1.1
168.19.100.198 → 1.1.1.3
169.0.0.0 → 1.1.1.5

Could not Understand what to do, how to do, did my best, but something was off with this question, had to ask interviewer to spare me and wasting his time

Comments (2)