Medium · Backtracking
Restore IP Addresses
Given a string digits made only of decimal digits, return every valid IPv4 address that can be formed by inserting exactly three dots into it without reordering or removing digits, in any order; a valid address is four integers 0–255 with no leading zeros (a lone 0 is fine).
Examples
Example 1
{
"digits": "25525511135"
}Output: 2 addresses
Example 2
{
"digits": "0000"
}Output: 1 address
Rebuild it in the studio
Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.