← Google Interview Insights

Google·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Jul 2026

Summary

Google coding interview with a single IP address validation problem. Pretty standard technical screen, nothing too wild, but the edge cases will get you if you're not careful.

Questions Asked (1)

Q1

Write a function to validate whether a given string is a valid IPv4 or IPv6 address.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

The core logic isn't hard but I kept second-guessing myself on the edge cases.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the exact requirements for IPv4 and IPv6 validation, including edge cases like leading zeros and compressed forms. Then design a modular solution that first determines the address family and applies the appropriate validation rules. Finally, discuss trade-offs between using built-in libraries versus implementing custom validation, and consider performance implications.

Pro tip: Demonstrate awareness of real-world constraints: mention that in production, you'd likely use a well-tested library like Python's ipaddress or Java's InetAddress, but implementing from scratch shows deeper understanding. Also, explicitly handle edge cases like IPv4-mapped IPv6 addresses and leading zeros in IPv4.

1. Clarify Requirements and Edge Cases

Ask clarifying questions to define what constitutes a valid IPv4 and IPv6 address, including whether to accept leading zeros, compressed IPv6 forms, and IPv4-mapped IPv6 addresses. This ensures alignment with the interviewer's expectations.

2. Design the Validation Strategy

Outline a plan to first detect the address family (IPv4 or IPv6) based on the presence of colons or dots. Then, for each family, define the validation rules: IPv4 requires four decimal octets 0-255 without leading zeros; IPv6 requires eight groups of hexadecimal digits, with rules for compression and embedded IPv4.

3. Implement the Validation Logic

Write clean, modular code with separate functions for IPv4 and IPv6 validation. Use helper functions to validate octets, groups, and handle compression. Ensure to cover all edge cases identified in step 1.

4. Test with Representative Cases

Walk through test cases for valid and invalid addresses, including boundary cases like '0.0.0.0', '255.255.255.255', '::1', '2001:db8::1', and invalid ones like '256.0.0.1', '1.2.3', '2001:db8::1::1'. This demonstrates thoroughness.

5. Discuss Trade-offs and Alternatives

Compare your custom implementation with using built-in libraries, highlighting pros (control, no dependencies) and cons (potential bugs, maintenance). Mention performance considerations and when to prefer each approach.

Key Points to Mention

  • IPv4 validation: four octets separated by dots, each 0-255, no leading zeros (except '0' itself).
  • IPv6 validation: eight groups of 1-4 hexadecimal digits, separated by colons; '::' can appear only once to represent one or more groups of zeros.
  • Edge cases: leading zeros in IPv4, IPv4-mapped IPv6 addresses (e.g., ::ffff:192.0.2.128), and compressed IPv6 forms.
  • Trade-offs: custom implementation vs. using standard libraries (e.g., Python's ipaddress, Java's InetAddress) in terms of reliability, performance, and code maintainability.
  • Time and space complexity: O(n) time where n is the length of the string, O(1) extra space for validation.
  • Testing strategy: include boundary values, invalid formats, and mixed formats to ensure robustness.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.