Where do the dots go?

Each level chooses how many digits the next part takes. After three dots, the rest is the last part.

The Week 3 template with a new kind of choice: 1, 2 or 3 digits. A part is only valid as a number from 0 to 255 with no leading zero, so most choices are rejected on the spot. Watch the outline grow: each row is one call, or one part that was turned down and why.

    ans
    being tried / rejected part accepted address recorded

    Press Next to start.

    Call stack

      LC 93

      Three ways a part is rejected

      Leading zero: "01" or "00" are not numbers an address can contain, though a lone "0" is. Over 255: "256". Too long: only the last part can be, since the loop never takes more than 3 digits; after three dots the whole tail is checked, and a tail of 4+ digits fails. Pick "010010": the leading 0 forces the first part to be just 0, and most later choices die on the same rule.

      A choice is only valid if the part it makes is a legal number.

      No un-choose step

      The code passes cur + segment + "." to the child: a new string, so the parent's cur never changes and there is nothing to pop. That's the same trade-off as LC 17. The loop also keeps at least one digit for later (idx + i < s.length()), which is why the outline never shows a call left with nothing to split.