• Tutorials
  • DSA
  • Data Science
  • Web Tech
  • Courses
August 21, 2024 |10 Views

PROBLEM OF THE DAY : 06/08/2024 | Validate an IP Address

Description
Discussion

Welcome to the daily solving of our PROBLEM OF THE DAY with Gaurav Patel We will discuss the entire problem step-by-step and work towards developing an optimized solution. This will not only help you brush up on your concepts of Strings but also build up problem-solving skills.

You are given a string str in the form of an IPv4 Address. Your task is to validate an IPv4 Address, if it is valid return true otherwise return false.

IPv4 addresses are canonically represented in dot-decimal notation, which consists of four decimal numbers, each ranging from 0 to 255, separated by dots, e.g., 172.16.254.1

A valid IPv4 Address is of the form x1.x2.x3.x4 where 0 <= (x1, x2, x3, x4) <= 255. Thus, we can write the generalized form of an IPv4 address as (0-255).(0-255).(0-255).(0-255)

Note: Here we are considering numbers only from 0 to 255 and any additional leading zeroes will be considered invalid.

Examples :

Input: str = 222.111.111.111
Output: true
Explanation: Here, the IPv4 address is as per the criteria mentioned and also all four decimal numbers lies in the mentioned range.
 

Give the problem a try before going through the video. All the best!!!
Problem Link: https://practice.geeksforgeeks.org/problems/validate-an-ip-address-1587115621/1