Recover Every Valid IPv4 Address From a Log Field Missing Its Dots
Last updated: November 29, 2026
Quick Overview
A log pipeline bug stripped the dots from IPv4 addresses, leaving strings like "25525511135". Return every valid dotted-quad address that the digit string could have come from, where each octet is 0 to 255 with no leading zeros.
0
0
0 solved
A log pipeline bug stripped the dots from IPv4 addresses, leaving strings like "25525511135". Return every valid dotted-quad address that the digit string could have come from, where each octet is 0 to 255 with no leading zeros.
A Google phone screen backtracking problem dressed as a data-recovery task. The interviewer wants a clean recursive search with tight pruning based on remaining length, and careful octet validation for the leading-zero rule.
What the Interviewer Expects
- Frames the problem as choosing three cut points
- Uses backtracking over octet lengths 1 to 3
- Validates octets: 0 alone is fine, other leading zeros are not, max 255
- Prunes when the remaining digits cannot fill the remaining octets
- States the constant upper bound on results and work
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Do the same for IPv6 groups without colons; why does the output explode?
- Return only addresses that fall in a given CIDR block.
- Write it iteratively with three nested loops and compare readability.
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input: a string of digits. Output: all valid addresses in any order.
- Each octet is
0or a number from 1 to 255 without a leading zero. - Use every digit exactly once and in order.
- Strings shor...
High-Level Design
We choose where the three dots go. Recursively take the next octet of length 1, 2, or 3, validate it, and recurse on the rest. The pruning rule is what keeps the search tiny: with need octets left, ...