Validate IPv4 and IPv6 Addresses in Azure Firewall Rules

Last updated: November 29, 2026

Quick Overview

Given a string from an Azure Firewall rule, return "IPv4" if it is a valid dotted-decimal IPv4 address, "IPv6" if it is a valid full-form IPv6 address with eight hex groups, and "Neither" otherwise.

Microsoft
Coding & Algorithms
Software Engineer
Microsoft
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Medium

0

0

0 solved


Given a string from an Azure Firewall rule, return "IPv4" if it is a valid dotted-decimal IPv4 address, "IPv6" if it is a valid full-form IPv6 address with eight hex groups, and "Neither" otherwise.

A common Microsoft phone screen warm-up for networking-adjacent teams such as Azure Networking, where malformed rule input must be rejected before it reaches the data plane. The interviewer is checking careful case analysis: leading zeros, empty groups, out-of-range values and stray characters, not cleverness.

What the Interviewer Expects
  • Split on the delimiter and check the exact group count
  • Reject leading zeros and values above 255 in IPv4
  • Accept 1 to 4 hex digits per IPv6 group, in either case
  • Avoid regex or library shortcuts unless the interviewer allows them
  • Enumerate tricky inputs out loud before coding
Key Topics to Cover
string parsing
input validation
IPv4
IPv6
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 accept compressed IPv6 forms like 2001:db8::1?
  • How would you validate a CIDR block such as 10.0.0.0/8?
  • Why is str.isdigit() unsafe for this check in Python?
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 single string with no surrounding whitespace guarantees. IPv4 means exactly four decimal groups separated by dots, each 0 to 255 with no leading zeros ("0" is fine, "01" is not). IPv6 here ...

High-Level Design

Dispatch on the delimiter, then validate group by group. str.split keeps empty strings, which is exactly what we want: "1.2.3." splits into four parts with one empty, and the length check on each ...


Submit Your Answer
Markdown supported