All problems
0247MediumStringBacktracking

Panel Address Splits

Tracked in this browser only
Write code

Trains the technique from

LeetCode 93Restore IP Addresses

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

A relay panel is identified by four numeric fields joined with -, for example 12-7-0-240. Each field is held in a single byte, so its value runs from 0 to 255, and each field is written in its shortest form: either the single digit 0, or a number whose first digit is not 0.

A technician copied a panel address down without the separators, leaving only digits, a string of decimal digits.

Return every panel address that produces exactly digits once its three separators are dropped, in any order. Return an empty list when no address produces it.

Examples

Example 1

Input
digits = "01203"
Output
["0-12-0-3", "0-1-20-3"]

Both addresses reproduce 01203 when the separators come out, and each of their fields is either a lone 0 or a number that does not open with 0.

Example 2

Input
digits = "10203"
Output
["10-2-0-3", "1-0-20-3"]

Every field shown lies between 0 and 255 and none opens with a 0 it does not need, so both addresses qualify.

Example 3

Input
digits = "9"
Output
[]

Four fields need at least four digits between them, and only one digit was copied down.

Constraints

  • 1 <= digits.length <= 20
  • digits consists of decimal digits only

The values you return may be in any order.

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def panel_addresses(digits: str) -> list[str]:
Java
public List<String> panelAddresses(String digits)
September 7
Apply