FastPrepConsistent-Hash Packet Router
Problems/Consistent-Hash Packet Router

Consistent-Hash Packet Router

Amazon logoAmazon● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionExamples

Problem statement

Source note: Reported in an Amazon SDE II phone screen. The task was to send each network packet, named by its source address and port, to one of the active backend servers so that the same packet always lands on the same server, and then to keep most assignments in place as servers join and leave.

The report leaves the hash function open, and its sample outputs depend on it. Here, every name is hashed with a fixed formula given in the statement, each server has one point on a ring, and a packet goes to the first server clockwise from its own point. The joins, leaves and packets come as one list of operations. We use up to 1000 starting servers and 2000 operations.

Our version is about 80% the same as the reported question.

You are building the router that sends incoming network packets to backend servers. A packet is named by its source address and port, such as "192.168.1.1:8080". The same packet must always go to the same server while the set of active servers stays the same, and when servers join or leave, as few packets as possible should change servers.

Every server ID and packet identifier gets a position on a ring from a fixed hash. Start with x = 0; for each character from left to right, set x = (x * 31 + c) mod 1000000007, where c is the character's ASCII code. The final x is the position. Positions go from 0 to 1000000006 and increase clockwise, and the ring wraps from the largest position back to 0.

The problem statement continues
Pro

Examples

Example 1

servers = ["server1","server2","server3"]operations = ["ROUTE","ROUTE","ROUTE"]values = ["192.168.1.1:8080","10.0.0.5:8080","192.168.1.1:8080"]return = ["server1","server1","server1"]
  • The servers sit at positions 63364207, 63364208 and 63364209.
  • "192.168.1.1:8080" hashes to 938097709 and "10.0.0.5:8080" to 743524288. No server is at or after either position, so both wrap to the smallest position, "server1".
  • The repeated packet goes to the same server again.
02 · Example 2
FastPrep Pro
Reported in 1 Amazon interview this week

Unlock this recently reported problem

FastPrep Pro gives you full access to interview problems reported within the last week.

  • Full problem statement and constraints
  • 2 more worked examples, explained
  • Guided hints and editorial
  • Run your code on real test cases
$8.25/month

$99 billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week

More Amazon Phone Screen questions

  • LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Course Schedule IIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Minimum Time to Spread Through a GridPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Count Connected ComponentsPHONE SCREEN · Seen Nov 2026
  • Second Largest Distinct ElementPHONE SCREEN · Seen Nov 2026
  • Task SchedulerOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Top K Frequent ElementsOA · PHONE SCREEN · Seen Nov 2026
  • Number of IslandsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • 3SumPHONE SCREEN · Seen Nov 2026

Similar questions at other companies

  • Interview Slot BookingTrueFoundry · PHONE SCREEN
  • Bank Accounts with Balance HistoryMeta · OAMeta interview questions
  • Key-Value Store with Hit CounterDatabricks · ONSITE INTERVIEWDatabricks interview questions
  • Banking System with Historical SnapshotsCoinbase · OACoinbase interview questions
  • In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
  • LRU CacheServiceNow · PHONE SCREEN · ONSITE INTERVIEWServiceNow interview questions
  • Mutable Points in a Hash Set and a ListMillennium · PHONE SCREENMillennium interview questions
  • Snapshot Map with Sparse Version HistorySnorkel AI · PHONE SCREEN
  • Rectangle Point Coverage CountsOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
  • File Storage ServiceCresta · PHONE SCREENCresta interview questions

Interview reports that mention this question

  • Amazon SDE II and L5 FDE Interview Questions: 4 Experiences

Amazon interview experiences

  • Amazon Experienced SDE Onsite Questions: 1 Experience
  • Amazon SDE Onsite Interview Questions: 9 Experiences
  • Amazon Full-Time OA Problems, Earlier Reports (Part 5 of 5)
  • Amazon Full-Time OA Problems, Recent Reports (Part 4 of 5)
  • Amazon New Grad OA Problems: Every Task We Have (Part 3 of 5)
See Amazon hiring insights
CodePython 3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import heapq
from collections import defaultdict
 
class Solution:
def solve(self, values, queries):
# Build the adjacency structure
n = len(values)
graph = defaultdict(list)
for u, v in queries:
graph[u].append(v)
 
best = [float("inf")] * n
heap = [(0, 0)]
while heap:
cost, node = heapq.heappop(heap)
if cost > best[node]:
continue
Run and Submit unlock with Pro
FastPrep Pro
Reported in 1 Amazon interview this week

Unlock this recently reported problem

FastPrep Pro gives you full access to interview problems reported within the last week.

  • Full problem statement and constraints
  • 2 more worked examples, explained
  • Guided hints and editorial
  • Run your code on real test cases
$8.25/month

$99 billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week