Reported August 2020
Postmanstring

Validate IP Address

Reported by candidates from Postman's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Postman OA. Under 2s to a working solution.
Founder's read

Postman reported this one in August 2020, and it looks like a gentle warm-up until you hit the edge cases. Validate IP Address really reduces to string splitting plus strict per-segment checks. No algorithm, no data structure, just discipline. If your OA invite is sitting there, expect to lose points on empty segments, leading zeros, and a stray character, not on the idea. If you blank mid-assessment, StealthCoder runs invisibly as a desktop overlay and can hand you a clean solution while the proctor sees nothing.

The problem

Given a string queryIP, return "IPv4" if it is a valid IPv4 address, "IPv6" if it is a valid IPv6 address, or "Neither" otherwise.
IPv4 rules
The address contains exactly four decimal segments separated by..
Each segment is an integer from 0 through 255.
A segment has no leading zero unless it is exactly 0.
Every character in a segment is a decimal digit.
IPv6 rules
The address contains exactly eight groups separated by :.
Each group contains one to four hexadecimal characters.
Hexadecimal letters may be lowercase or uppercase.
Leading zeroes are allowed, but an empty group is not.

Function
validIPAddress(queryIP: String) → String

Examples
Example 1
queryIP = "172.16.254.1"
return = "IPv4"
The address has four decimal segments, each is in range, and none has an invalid leading zero.
Example 2
queryIP = "2001:0db8:85a3:0:0:8A2E:0370:7334"
return = "IPv6"
The address has eight non-empty hexadecimal groups, and every group contains at most four characters.
Example 3
queryIP = "256.256.256.256"
return = "Neither"
Every segment is greater than 255, so this is not a valid IPv4 address.

Constraints
queryIP is a non-empty string.
queryIP contains only English letters, decimal digits,., and :.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick: decide the type first, then validate. If the string contains a dot, treat it as an IPv4 candidate. If it contains a colon, treat it as IPv6. Otherwise return Neither. Split on the delimiter with a split that keeps empty tokens, because a trailing dot or colon must produce an empty segment that fails. For IPv4, require exactly four parts, all digits, no leading zero unless the part is exactly 0, and a value of 255 or less. For IPv6, require exactly eight parts, each 1 to 4 characters, all in 0-9, a-f, A-F. The pitfalls are language defaults that drop trailing empties, parsing ints on non-digit input, and accepting a segment like 01 or an empty group. Write small helper functions for each check. If the live OA rattles you, StealthCoder is the safety net that reads the problem and gives you working code.

If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.

If this hits your live OA

You can drill Validate IP Address cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as validate ip address. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass Postman's OA.

Postman reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Validate IP Address FAQ

How hard is Validate IP Address really?+

Easy on concept, annoying on edge cases. There's no clever algorithm. You split the string and check each piece against the rules. Most failed submissions come from leading zeros, empty segments, or trailing delimiters, not from the main logic.

What's the trick to getting it right the first time?+

Branch on the delimiter, then validate every segment with a strict helper. Check length first, then character set, then leading zero, then numeric range. Write the checks in that order and the edge cases fall out naturally.

Should I use regex or manual parsing?+

Manual parsing is safer under pressure. A regex for the 0-255 range with no leading zeros is easy to get wrong, and hard to debug. Splitting and checking each segment is longer but far more predictable, and easier to explain.

Which edge cases should I test before submitting?+

Test a trailing dot, a trailing colon, a segment like 01, a segment of 256, an empty IPv6 group, a five-character hex group, and a non-hex letter like g. Also test a string with neither delimiter. Those cases catch most wrong answers.

How do I prepare for this in 48 hours?+

Write the solution once from scratch without looking, with separate IPv4 and IPv6 helpers. Then run the edge cases above by hand. String validation problems like this reward clean structure, and one careful pass is enough.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Postman.

OA at Postman?
Invisible during screen share
Get it