Timer is Running

Generate IP Addresses
Submissions: 8593   Accuracy:

34.06%

  Difficulty: Medium   Marks: 4

Given a string S containing only digits, Your task is to complete the function genIp() which returns a vector containing all possible combination of valid IPv4 ip address and takes only a string S as its only argument.
Note : Order doesn't matter.

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 1:

Input:
S = 1111
Output: 1.1.1.1


Your Task:

Your task is to complete the function genIp() which returns a vector containing all possible combination of valid IPv4 ip address in sorted order and takes only a string S as its only argument.

Expected Time Complexity: O(N * N * N * N)
Expected Auxiliary Space: O(N * N * N * N)

Constraints:
1<=N<=16
here, N = length of S.
S only contains digits(i.e. 0-9)

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Harshit Sidhwa
Author: Shubham Joshi 1


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.