Validate IPv4 Address List
Company: Okta
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: This question evaluates proficiency in string parsing, input validation, numeric boundary checks, and algorithmic complexity by requiring verification of IPv4 address formatting across a list of strings.
Constraints
- 0 <= len(addresses) <= 10^4
- 0 <= len(addresses[i]) <= 50
- The total number of characters across all strings is at most 2 * 10^5
Examples
Input: (['192.168.1.1', '8.8.8.8'],)
Expected Output: True
Explanation: Both strings have exactly four numeric parts, each between 0 and 255, with no invalid leading zeros.
Input: (['1.2.3.256'],)
Expected Output: False
Explanation: The last part is 256, which is outside the allowed range 0 to 255.
Input: (['01.2.3.4'],)
Expected Output: False
Explanation: The first part has a leading zero, which is not allowed.
Input: (['1..2.3'],)
Expected Output: False
Explanation: There is an empty part between the two dots.
Input: ([],)
Expected Output: True
Explanation: There are no invalid addresses in an empty list, so the condition is vacuously true.
Input: (['0.0.0.0', '255.255.255.255', '10.20.30.40'],)
Expected Output: True
Explanation: These are all valid IPv4 addresses, including the boundary values 0 and 255.
Input: (['1.2.3.4', '1.2.3.a'],)
Expected Output: False
Explanation: The second address contains a non-digit character `a`.
Hints
- Process each address one part at a time using `.` as the separator.
- While scanning a part, track its numeric value and reject it immediately if it becomes larger than 255 or has a leading zero.