Classify Log Addresses as IPv4, IPv6, or Neither With Compression
Last updated: November 29, 2026
Quick Overview
Given a string from a request log, return "IPv4", "IPv6", or "Neither", supporting dotted-quad IPv4 without leading zeros and full IPv6 syntax including a single :: compression and an embedded IPv4 tail such as ::ffff:192.168.1.1.
0
0
0 solved
Given a string from a request log, return "IPv4", "IPv6", or "Neither", supporting dotted-quad IPv4 without leading zeros and full IPv6 syntax including a single :: compression and an embedded IPv4 tail such as ::ffff:192.168.1.1.
Google Cloud load balancers and logging pipelines must validate client addresses, and this onsite question goes beyond the simple version by requiring IPv6 compression. The interviewer evaluates whether you turn a messy spec into a few precise rules and test the boundaries methodically.
What the Interviewer Expects
- States the exact rules for both families before coding
- Rejects leading zeros, out-of-range octets, and non-ASCII digits in IPv4
- Handles at most one :: and counts groups correctly with and without it
- Treats an embedded IPv4 tail as two IPv6 groups
- Builds a test list that covers each rule
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
- Return the canonical compressed IPv6 form (RFC 5952) of a valid address.
- Parse CIDR blocks like 10.0.0.0/8 and check whether an address is inside one.
- Would you use a regex here? What are the risks in a production validator?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- IPv4: exactly four decimal parts, each
0..255, no leading zeros (01is rejected because some parsers treat it as octal), ASCII digits only. - IPv6: eight groups of 1 to 4 hex digits separated by...
High-Level Design
Write two independent validators and try IPv4 first. For IPv4, split on dots and check each part. For IPv6, first reject more than one ::. If the string contains a dot, validate the part after the l...