Solution: Restore IP Addresses

Let's solve the Restore IP Addresses problem using the Backtracking pattern.


Given that a string, s, contains digits, return a list of all possible valid IP addresses that can be obtained from the string.

Note: The order in which IP addresses are placed in the list is not important.

A valid IP address is made up of four numbers separated by dots ., for example, Each number falls between 00 and 255255 (including 00 and 255255), and none of them can have leading zeros.


  • The input string s consists of digits only.

  • 44 \leq s.length 12\leq 12

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.