PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

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.

  • medium
  • Okta
  • Coding & Algorithms
  • Software Engineer

Validate IPv4 Address List

Company: Okta

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are given an array of strings `addresses`. Return `true` if **every** string in the array is a valid IPv4 address; otherwise return `false`. An IPv4 address is valid if: - it contains exactly four parts separated by `.` - each part is non-empty and contains only decimal digits - each part represents a value from `0` to `255` - leading zeros are not allowed unless the part is exactly `0` Examples: - `['192.168.1.1', '8.8.8.8']` -> `true` - `['1.2.3.256']` -> `false` - `['01.2.3.4']` -> `false` - `['1..2.3']` -> `false` Aim for a solution that runs in linear time in the total number of characters across all strings.

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.

You are given an array of strings `addresses`. Return `True` if every string in the array is a valid IPv4 address; otherwise return `False`. An IPv4 address is valid if: - it contains exactly four parts separated by `.` - each part is non-empty and contains only decimal digits - each part represents a value from `0` to `255` - leading zeros are not allowed unless the part is exactly `0` If the input array is empty, return `True`.

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

  1. Process each address one part at a time using `.` as the separator.
  2. While scanning a part, track its numeric value and reject it immediately if it becomes larger than 255 or has a leading zero.
Last updated: May 7, 2026

Related Coding Questions

  • Deduplicate an Array in Linear Time - Okta

Loading coding console...

PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.