Problem 236731 · easy · Phase 02 Linear Data Structures

Dotted Quad Check

strings · validation

Write is_ipv4(s) that returns True if s is a valid IPv4 address in dotted-decimal notation:

  • exactly four parts separated by .
  • each part consists only of digits, has length 1 to 3, and its value is between 0 and 255
  • no part has a leading zero unless the part is exactly "0"
  • no extra characters or spaces anywhere

Examples

Input:  s = "192.168.1.1"
Output: True

Input:  s = "256.1.1.1"
Output: False

Input:  s = "01.2.3.4"
Output: False
Explanation: leading zero.

Constraints

  • 0 <= len(s) <= 50, printable ASCII only

Goals

  • Split on a separator and check the piece count
  • Validate numeric text without int() surprises
  • Reject leading zeros explicitly
Starting Python…