PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

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).

  • medium
  • Figma
  • Coding & Algorithms
  • Data Engineer

Validate an IPv4 address string

Company: Figma

Role: Data Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

Given a string `s`, determine whether it is a valid IPv4 address. A valid IPv4 address: - Has exactly 4 parts separated by dots (`.`): `x1.x2.x3.x4` - Each part is a base-10 integer in the range `[0, 255]` - No extra characters are allowed (only digits and dots) Examples: - Valid: `"192.168.1.1"`, `"192.168.1.0"` - Invalid: `"192.168.100.1.1"` (5 parts), `"192.1681.1"` (missing dot separation) Write a function that returns `True` if `s` is a valid IPv4 address and `False` otherwise.

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).

Given a string `s`, determine whether it is a valid IPv4 address. A valid IPv4 address: - Has exactly 4 parts separated by dots (`.`): `x1.x2.x3.x4` - Each part is a base-10 integer in the range `[0, 255]` - No extra characters are allowed (only digits and dots) - A part may not have a leading zero (e.g. `01` or `00` is invalid), and an empty part (e.g. from `192.168..1`) is invalid Return `true` if `s` is a valid IPv4 address and `false` otherwise. Examples: - Valid: `"192.168.1.1"`, `"192.168.1.0"`, `"0.0.0.0"`, `"255.255.255.255"` - Invalid: `"192.168.100.1.1"` (5 parts), `"192.1681.1"` (missing dot separation), `"256.1.1.1"` (octet > 255), `"192.168.01.1"` (leading zero)

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.

Input: ("0.0.0.0",)

Expected Output: True

Explanation: Minimum address; single-digit zeros are allowed.

Input: ("255.255.255.255",)

Expected Output: True

Explanation: Maximum address; 255 is the upper bound.

Input: ("192.168.100.1.1",)

Expected Output: False

Explanation: Five parts — an IPv4 address must have exactly four.

Input: ("192.1681.1",)

Expected Output: False

Explanation: Only three parts because a dot is missing.

Input: ("256.1.1.1",)

Expected Output: False

Explanation: 256 exceeds the maximum octet value of 255.

Input: ("1.1.1",)

Expected Output: False

Explanation: Only three parts.

Input: ("",)

Expected Output: False

Explanation: Empty string splits into one empty part, not four.

Input: ("192.168.01.1",)

Expected Output: False

Explanation: '01' has a leading zero, which is invalid.

Input: ("192.168..1",)

Expected Output: False

Explanation: Consecutive dots produce an empty octet, which is invalid.

Input: ("abc.def.ghi.jkl",)

Expected Output: False

Explanation: Parts must be base-10 digits, not letters.

Input: ("-1.0.0.0",)

Expected Output: False

Explanation: '-1' is not all digits and is out of range.

Input: ("192.168.1.1 ",)

Expected Output: False

Explanation: A trailing space makes the last part '1 ', which is not all digits.

Hints

  1. Split the string on '.' and immediately reject anything that does not produce exactly 4 parts.
  2. 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.
  3. Using s.split('.') keeps empty parts (e.g. '192.168..1' yields a '' part), so an explicit emptiness check catches the double-dot case.
Last updated: Jun 26, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ 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
  • AI Coding 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.

Related Coding Questions

  • Implement Layer History and Grid Counting - Figma (medium)
  • Write SQL for first share and closest collaborator - Figma (medium)
  • Design document layer with undo/redo - Figma (Medium)
  • Design document editor with undo/redo and batching - Figma (Medium)