FastPrepRestore Addresses with K Segments
Problems/Restore Addresses with K Segments

Restore Addresses with K Segments

ByteDance logoByteDance● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The interview report gives the standard task of restoring valid addresses and a follow-up with any number of segments. It does not say the output order, the limits or the function format. Our version, with the follow-up, is about 97% the same as the reported question.

You are given a string digits containing only decimal digits and an integer segmentCount.

Insert exactly segmentCount - 1 dots so that every resulting segment:

  • contains between one and three digits,
  • represents an integer from 0 through 255, and
  • has no leading zero unless the segment is exactly 0.

Return every valid dotted address in lexicographic order. Return an empty array when no valid address exists.

When segmentCount = 4, this is the standard restoration rule for IPv4 addresses; other values use the same segment rules.

Function

restoreAddresses(digits: String, segmentCount: int) → String[]

Examples

Example 1

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

Both outputs have four valid segments, and no other placement satisfies the value and leading-zero rules.

Example 2

digits = "010010"segmentCount = 4return = ["0.10.0.10","0.100.1.0"]

A segment beginning with 0 must be exactly 0, which eliminates placements such as 01.

Example 3

digits = "1234"segmentCount = 2return = ["1.234","12.34","123.4"]

With two segments, the dot may follow the first, second, or third digit, and every resulting segment remains at most 255.

Constraints

  • 1 ≤ digits.length ≤ 30.
  • digits contains only decimal digits.
  • 1 ≤ segmentCount ≤ 10.
  • The total number of returned characters fits in memory.

More ByteDance Phone Screen questions

  • Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
  • Implement QuicksortPHONE SCREEN · Seen Dec 2026
  • Largest Rectangle in HistogramPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
  • Reverse Linked ListPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
  • Count N-Queens PlacementsPHONE SCREEN · Seen Nov 2026
  • Matrix EscapePHONE SCREEN · Seen Nov 2026
  • Largest Number Below N from Reusable DigitsPHONE SCREEN · Seen Nov 2026
  • Log Analyzer: Busiest Service in a Rolling WindowPHONE SCREEN · Seen Nov 2026
  • Majority ElementPHONE SCREEN · Seen Nov 2026
  • Valid ParenthesesPHONE SCREEN · Seen Nov 2026

Similar questions at other companies

  • All English Decodings of Morse CodeOscar Health · PHONE SCREEN
  • Phone-Number Letter CombinationsHeadway · PHONE SCREENHeadway interview questions
  • Letter Combinations of a Phone NumberLinkedIn · PHONE SCREENLinkedIn interview questions
  • String Permutations in Custom Character OrderWex · OA · PHONE SCREEN
  • Numeric Poker OperationsRippling · PHONE SCREENRippling interview questions
  • Unique String PermutationsAmazon · PHONE SCREEN
  • Permutations of Unique CharactersSalesforce · PHONE SCREENSalesforce interview questions
  • Count Prefix Paths in a Character GraphGoogle · PHONE SCREENGoogle interview questions
  • Sorted Subsets of a StringMicrosoft · PHONE SCREENMicrosoft interview questions
  • Maximum Unique Substring SplitThe Walt Disney Company · PHONE SCREENThe Walt Disney Company interview questions

ByteDance interview experiences

  • ByteDance TikTok USDS SWE Intern Interview: 1 Experience
  • ByteDance MLE New Grad Interviews: 1 Experience
  • ByteDance Security SRE Intern Phone Screens: 1 Experience
  • ByteDance USDS New Grad SWE Phone Screen: 1 Experience
  • ByteDance New Grad Data Engineer Video Interviews: 1 Experience
  • ByteDance Trust & Safety Research Scientist Intern: 1 Experience
All ByteDance interview questionsSee ByteDance hiring insights
Saved
class Solution {
    public String[] restoreAddresses(String digits, int segmentCount) {
        // Write your code here.
    }
}
Checking account…