93. Restore IP Addresses

Practice Restore IP Addresses for free on NudgeCode: Medium, Backtracking pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.

s is a string of digits. Put exactly three dots into it so it splits into four parts that form a valid IPv4 address, without adding, removing or reordering any digit. Each part must be an integer from 0 to 255, and a part may not start with 0 unless it is just 0 (01 is not allowed). Return every address you can make, in any order.

Example

s = "25525511135"  ->  ["255.255.11.135","255.255.111.35"]

Constraints