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
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

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
Backtracking
String parsing
Pruning
Validation
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 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 Problems
Sample Answer
Requirements
  • Input is a string of 0 to 20 characters.
  • Output every distinct address, any order.
  • Parts are decimal 0 to 255; 0 is fine, 01 is 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...


Submit Your Answer
Markdown supported