Restore IP Addresses

Given an ASCII digit string digits, insert exactly three dots to restore every valid IPv4 address. Use every digit once in its original order. Each of the…

Given an ASCII digit string digits, insert exactly three dots to restore every valid IPv4 address. Use every digit once in its original order. Each of the four nonempty contiguous octets must represent an integer from 0 through 255, and a multi-digit octet cannot begin with zero. Return every valid address exactly once, in any order. Return an empty list when no split works.

- 1 <= digits.length <= 20; every character is an ASCII digit 0 through 9. - Lengths below 4 or above 12 are valid inputs with an empty answer. - Return a native list/array of strings. Missing, extra or duplicate addresses are incorrect. - Existing dots, signs, whitespace, Unicode digits, IPv6 and host names are outside the input contract.

Example 1: input digits = "25525511135"; output ["255.255.11.135","255.255.111.35"]. These are the only two three-cut splits with four legal octets.

Example 2: input digits = "010010"; output ["0.10.0.10","0.100.1.0"]. The initial zero must stand alone; internal zeroes remain legal.

Example 3: input digits = "00000"; output []. Five zeroes cannot form four octets without an invalid leading zero.

Category: Recursion. Topic: recursion. Difficulty: Medium. Patterns: backtracking, string-processing.