FastPrepRestore IP Addresses

Restore IP Addresses

Motive logoMotive● MediumFULLTIMEONSITE INTERVIEW
Learn

Problem statement

Given a string digits containing only decimal digits, return every valid IPv4 address obtained by inserting exactly three dots. Return the addresses in lexicographic order.

Each segment must be from 0 through 255 and cannot have a leading zero unless it is exactly 0.

Function

restoreIpAddresses(digits: String) → String[]

Examples

Example 1

digits = "25525511135"return = ["255.255.11.135","255.255.111.35"]

Example 2

digits = "0000"return = ["0.0.0.0"]

Constraints

  • 1 <= digits.length <= 20.

More Motive problems

See Motive hiring insights
public String[] restoreIpAddresses(String digits) {
  // write your code here
}
digits"25525511135"
expected["255.255.11.135", "255.255.111.35"]
Checking account…