← Flexport Interview Insights

Flexport·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
May 2026

Summary

Flexport software engineer interview with a coding round focused entirely on IPv4 address validation and restoration. Three related subproblems, escalating in difficulty. The backtracking part at the end was where things got interesting.

Questions Asked (3)

Q1

Write a function that validates whether a given string is a correctly formatted dotted-decimal IPv4 address, handling edge cases like leading zeros, signs, and out-of-range values.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

Seemed straightforward at first and I almost rushed it.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the exact rules for a valid IPv4 address, then walk through a clean parsing strategy that splits on dots and validates each octet. Emphasize edge cases like leading zeros, signs, and range checks, and discuss trade-offs between regex and manual parsing.

Pro tip: Mention that leading zeros are invalid in standard dotted-decimal notation (e.g., '01' is not allowed), and that a regex alone can be error-prone for range validation—so a hybrid approach or manual parsing is often more maintainable.

1. Clarify requirements and edge cases

Confirm the definition of a valid IPv4 address: exactly four octets separated by dots, each octet is a decimal number 0-255 without leading zeros or signs. List edge cases like empty strings, extra dots, whitespace, and non-digit characters.

2. Choose a parsing strategy

Decide between regex, manual splitting, or a hybrid. Discuss trade-offs: regex is concise but can be hard to read and maintain for range checks; manual parsing is more explicit and easier to debug.

3. Implement validation logic

Split the string by '.', check there are exactly four parts, and for each part verify it's non-empty, contains only digits, has no leading zeros (unless it's '0'), and its integer value is between 0 and 255.

4. Test with edge cases

Walk through examples: valid ('192.168.0.1'), invalid leading zeros ('192.168.01.1'), out-of-range ('256.1.1.1'), signs ('+1.2.3.4'), and malformed ('1.2.3').

5. Discuss complexity and improvements

State time and space complexity (O(n) time, O(1) space for manual parsing). Mention potential improvements like using a compiled regex for performance or handling IPv6 separately.

Key Points to Mention

  • Exactly four octets separated by dots
  • Each octet must be a decimal number between 0 and 255
  • No leading zeros allowed (e.g., '01' is invalid)
  • No signs (+/-) or whitespace allowed
  • Trade-offs between regex and manual parsing
  • Time and space complexity of the solution

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q2

Given a string of digits with no dots, determine whether it's possible to insert exactly three dots to form a valid IPv4 address under the same validation rules.

Algorithms & Data Structures
Author's notes

This is basically part (a) but you have to figure out where to put the dots.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use backtracking to try all possible placements of three dots, validating each segment as you go. Prune branches early when a segment is invalid (leading zeros, value > 255, or empty). Return true if any valid partition is found.

Pro tip: Mention that you can optimize by limiting segment lengths to 1-3 digits and using a helper function to validate segments, which makes the code cleaner and easier to reason about. Also, discuss the time complexity: O(1) since the string length is at most 12 for a valid IPv4 address.

1. Understand the problem and constraints

Clarify that the input is a string of digits, and we need to insert exactly three dots to form four segments. Each segment must be a valid IPv4 octet: 0-255, no leading zeros unless the segment is '0'.

2. Choose an approach

Decide between backtracking, iterative nested loops, or recursion. Backtracking is intuitive and allows early pruning.

3. Implement validation and pruning

Write a helper to check if a substring is a valid octet. During recursion, only consider substrings of length 1 to 3, and skip if invalid.

4. Handle base cases and termination

Stop when three dots are placed and the remaining substring is valid, or when the string is exhausted. Return true if a valid partition is found.

5. Analyze complexity and edge cases

Discuss time complexity (constant due to max length 12) and test edge cases like leading zeros, segments > 255, and strings too short/long.

Key Points to Mention

  • IPv4 address consists of four octets separated by dots, each 0-255.
  • Leading zeros are not allowed unless the octet is '0'.
  • Backtracking with pruning is efficient because the search space is small.
  • Time complexity is O(1) because the maximum length of a valid IPv4 string is 12 (e.g., '255255255255').
  • Edge cases: strings shorter than 4 or longer than 12 cannot form a valid IPv4 address.
  • Use a helper function to validate segments to keep code modular.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q3

Return all valid IPv4 addresses that can be formed by inserting three dots into a digit-only string, without duplicates.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

This is where I fumbled a bit.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use backtracking to place three dots, validating each segment as a valid IPv4 octet (0-255, no leading zeros unless the segment is '0'). Prune early when a segment is invalid or when remaining characters cannot form the required number of segments.

Pro tip: Mention that you can avoid duplicates by ensuring segments are formed in order and never revisiting the same split; also discuss the trade-off between backtracking and iterative nested loops for exactly 3 dots.

1. Clarify constraints and edge cases

Confirm that the input is a digit-only string, that segments must be 1-3 digits, and that leading zeros are invalid except for '0'. Discuss handling of empty strings or strings shorter than 4 or longer than 12 characters.

2. Choose an algorithm

Select backtracking to recursively place dots, or iterative nested loops for exactly 3 dots. Explain why backtracking is more general and easier to prune.

3. Define validity and pruning

For each segment, check length 1-3, value 0-255, and no leading zeros. Prune when remaining characters cannot form the remaining segments (e.g., too few or too many digits).

4. Implement and avoid duplicates

Build the IP by appending segments with dots. Since splits are unique, duplicates won't occur; but if using a set, explain why it's unnecessary.

5. Analyze complexity and test

Time complexity is O(1) due to fixed 3 dots and max 12 digits; space O(1) for output. Test with examples like '25525511135' and edge cases like '0000' and '1111'.

Key Points to Mention

  • Backtracking with pruning based on segment validity and remaining length
  • Segment validation rules: 1-3 digits, 0-255, no leading zeros unless '0'
  • Avoiding duplicates by construction (ordered splits) rather than using a set
  • Time and space complexity: O(1) due to fixed number of dots and max input length
  • Edge cases: input length <4 or >12, strings with leading zeros, all zeros
  • Trade-off: iterative nested loops vs. recursive backtracking for exactly 3 dots

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.