Medium

Quiz

#93 Restore IP Addresses

APPROACH

A valid IPv4 address consists of four integers in [0, 255] separated by dots, with no leading zeros other than "0" itself. Given digit-only string s, return all valid IP addresses obtainable by inserting exactly three dots without reordering or removing any character. Results may be in any order.

Example 1:

Input: s = "25525511135"
Output: ["255.255.11.135","255.255.111.35"]

Example 2:

Input: s = "0000"
Output: ["0.0.0.0"]

Example 3:

Input: s = "101023"
Output: ["1.0.10.23","1.0.102.3","10.1.0.23","10.10.2.3","101.0.2.3"]
1 of 4
1:00

What is the optimal approach for this problem?