Validate an IPv4 address string
Company: Figma
Role: Data Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: Evaluates string parsing and input-validation skills, including digit-only checks, delimiter-based splitting, numeric range enforcement, and edge-case handling. Commonly asked to assess attention to input formats and robustness in implementation; Category: Coding & Algorithms; Level: implementation-level (concrete string manipulation and validation).
Constraints
- 1 <= len(s) <= 100 (s may also be empty, which is invalid)
- s consists of printable ASCII characters; only digits and '.' can appear in a valid address
- Octets must be in the range [0, 255] with no leading zeros
Examples
Input: ("192.168.1.1",)
Expected Output: True
Explanation: Standard valid address: 4 parts, each in [0,255].
Input: ("192.168.1.0",)
Expected Output: True
Explanation: 0 is a valid octet value.
Hints
- Split the string on '.' and immediately reject anything that does not produce exactly 4 parts.
- For each part: reject if it is empty, contains a non-digit character, has a leading zero (length > 1 and starts with '0'), or its integer value exceeds 255.
- Using s.split('.') keeps empty parts (e.g. '192.168..1' yields a '' part), so an explicit emptiness check catches the double-dot case.