Restore IP Addresses

Medium · Backtracking · about 20 minutes

Asked at Amazon, Microsoft, Google, Meta, ByteDance, Cisco, IBM, Arista Networks, Palo Alto Networks, Zscaler.

A valid IPv4 address is four integers from 0 to 255 separated by dots, with no leading zeros (so "0" is fine but "01" is not). Given a string s of digits, return every valid IP address that can be formed by inserting three dots into s (without reordering or removing digits), in any order.

Related guides