Restore Possible IPv4 Addresses From a Corrupted Log Digit String

Last updated: November 29, 2026

Quick Overview

A load balancer log lost the dots in client IP addresses, leaving only digits like `25525511135`. Return every valid IPv4 address that could produce the string by inserting three dots, with octets 0 to 255 and no leading zeros.

Amazon
Coding & Algorithms
Software Engineer
Amazon
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


A load balancer log lost the dots in client IP addresses, leaving only digits like `25525511135`. Return every valid IPv4 address that could produce the string by inserting three dots, with octets 0 to 255 and no leading zeros.

A technical-screen backtracking question in Amazon's style, framed around recovering client addresses from a damaged access log. It checks tight pruning by remaining length and careful octet validation.

What the Interviewer Expects
  • Backtracks over octet lengths 1 to 3
  • Rejects leading zeros except a lone 0
  • Rejects values above 255
  • Prunes when remaining digits cannot fill remaining octets
  • Bounds the search size explicitly
Key Topics to Cover
backtracking
string parsing
pruning
networking
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you adapt this to IPv6 with hex groups?
  • How would you rank candidates if you knew which subnets are common?
  • What is the maximum number of results and why?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input is a digit string of length 4 to 12 (anything else has no answers). Output all addresses using every digit exactly once, in any order....

High-Level Design

Choose four octets left to right. At each step try lengths 1, 2, 3. An octet is valid if it has no leading zero (unless it is exactly 0) and is at most 255. Two prunes keep the search tiny: if the r...


Submit Your Answer
Markdown supported