Parse an IP:PORT/PATH string into a validated IP address, port and path
Company: Okta
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: easy
Interview Round: Other
Overview: Split a string of the form IP:PORT/PATH into its IPv4 address, port and path, and return three Invalid markers when any part breaks the rules. It tests careful string splitting and range checks on octets and ports, including leading zeros, port zero and an empty path.
Constraints
- 1 <= len(s) <= 300
- s contains only digits, dots, colons, slashes and lowercase English letters.
- Any string within that alphabet and length is a valid input; a malformed one returns ["Invalid", "Invalid", "Invalid"].
Examples
Input: ('192.168.1.1:8080/api/v1/resource',)
Expected Output: ['192.168.1.1', '8080', '/api/v1/resource']
Explanation: Source example 1 (input length 32): every octet and port 8080 are in range, so the three parts come back as written.
Input: ('256.100.50.25:80/home',)
Expected Output: ['Invalid', 'Invalid', 'Invalid']
Explanation: Source example 2 (input length 21): octet 256 is one above 255, and the valid port and path do not change that.
Hints
- Find the two split positions first: the first ':' in the string, and the first '/' that comes after it. A '/' that appears before that colon does not count.
- Before looking at a number's value, check its form: it must be non-empty, all digits, and free of a leading zero unless it is exactly "0".
- A digit run can be hundreds of characters long. Decide how to reject an oversized octet or port without parsing it into a fixed-width integer.