...

/

Restore IP Addresses

Restore IP Addresses

Try to solve the Restore IP Addresses problem.

Statement

A valid IP address consists of four numeric segments separated by single dots. Each segment must be an integer between 0 and 255 (inclusive), and leading zeros are not allowed unless the segment is exactly ‘0.”

For instance, “10.0.1.25” and “172.16.0.5” are valid IP addresses, while “01.200.100.3,” “256.100.50.25,” and “172.16.0.500” are invalid.

Given a string s made up of digits only, return all possible valid IP addresses that can be created by inserting exactly three dots into the string. You cannot rearrange or delete any digits. The resulting list of valid IP addresses can be returned in any order.

Constraints:

  • The input string s consists of digits only.

  • 44 \leq s.length 12\leq 12

Examples

Understand the problem

Let’s take a moment to make sure you’ve correctly understood the problem. The quiz below helps you check if you’re solving the correct problem:

Technical Quiz
1.

What is the correct output if the following string is given as input?

IP address = “00000000”

A.

[“000.000.00”, “00.000.000”, “000.00.000”, “0.0.000.000”, “0.00.00.000”]

B.

[“000.000.00”]

C.

[“00.00.00.00”]

D.

None


1 / 4

Figure it out!

We have a game for you to play. Rearrange the logical building blocks to develop a clearer understanding of how to solve this problem.

Note: As an additional challenge, we have intentionally hidden the solution to this puzzle.

Sequence - Vertical
Drag and drop the cards to rearrange them in the correct sequence.

1
2
3
4
5

Try it yourself

Implement your solution in the following coding playground.

Java
usercode > Main.java
import java.util.*;
public class Main{
public static List<String> restoreIpAddresses(String s) {
// Replace this placeholder return statement with your code
return new ArrayList<String>();
}
}
Restore IP Addresses

Access this course and 1200+ top-rated courses and projects.