• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
January 03, 2024 |580 Views
SDE Sheet - Generate IP Addresses
  Share  1 Like
Description
Discussion

This video is part of the Backtracking section under the GFG SDE Sheet.

In this problem, we are given Given a string S containing only digits, Your task is to complete the function genIp() which returns a vector containing all possible combinations of valid IPv4 IP addresses and takes only a string S as its only argument.
Note: Order doesn't matter. A valid IP address must be in the form of A.B.C.D, where A, B, C, and D are numbers from 0-255. The numbers cannot be 0 prefixed unless they are 0.

For string 11211 the IP address possible are 
1.1.2.11
1.1.21.1
1.12.1.1
11.2.1.1

Example :

Input: S = 1111 Output: 1.1.1.1

Try it out before watching the implementation of the problem in the video. We recommend watching the video, even if you can solve the problem. You may discover something new. All the best!!!

Do check out:-
Article: https://www.geeksforgeeks.org/program-generate-possible-valid-ip-addresses-given-string/
Problem: https://www.geeksforgeeks.org/problems/generate-ip-addresses/1
SDE Sheet Link: https://www.geeksforgeeks.org/sde-sheet-a-complete-guide-for-sde-preparation/

Read More