Recover Every Valid IPv4 Address From a Log With Dots Stripped
Last updated: November 29, 2026
Quick Overview
A log pipeline stripped the dots from client IPv4 addresses, leaving only a digit string. Return every valid dotted address the string could have come from, where each of the four parts is 0 to 255 with no leading zeros.
Meta
November 29, 20260
0
0 solved
A log pipeline stripped the dots from client IPv4 addresses, leaving only a digit string. Return every valid dotted address the string could have come from, where each of the four parts is 0 to 255 with no leading zeros.
Meta security and integrity teams parse messy logs, and this framing tests bounded backtracking with careful validation. The interviewer looks for leading-zero handling, length-based pruning and a clear argument that the search space is tiny.
What the Interviewer Expects
- Enumerate segment lengths 1 to 3 per part
- Reject leading zeros and values above 255
- Prune when remaining characters cannot fill remaining parts
- Stop exactly at four parts and the end of the string
- Bound the search at 3^4 = 81 leaves
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
- How would you extend this to IPv6 with hex groups and the :: shorthand?
- How would you validate a single candidate address instead of generating all?
- How would you handle a string that might contain a port suffix?
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 is a string of 0 to 20 characters.
- Output every distinct address, any order.
- Parts are decimal 0 to 255;
0is fine,01is not....
High-Level Design
Place parts one by one. At each step try a segment of length 1, 2 or 3 starting at the current index. A segment is valid if it is a single digit, or it does not start with 0 and is at most 255. Befo...