FastPrepIterate Canonical IPv6 Addresses
Problems/Iterate Canonical IPv6 Addresses

Iterate Canonical IPv6 Addresses

OpenAI logoOpenAI● MediumFULLTIMEONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The interview report extends an earlier address iterator to IPv6 increment and decrement. It omits formatting and boundary rules; this practice version uses canonical eight-group output and guarantees all moves remain in range. The judged core task matches the visible report at about 85%.

start is an IPv6 address in canonical lowercase form: exactly eight groups of four hexadecimal digits separated by colons. Apply every value in moves cumulatively. A move of 1 increments the unsigned 128-bit address, and -1 decrements it.

Return the canonical address after each move. The input guarantees that no step underflows below zero or overflows above 2^128 - 1.

Function

moveIPv6Addresses(start: String, moves: int[]) → String[]

Examples

Example 1

start = "0000:0000:0000:0000:0000:0000:0000:00ff"moves = [1,1,-1]return = ["0000:0000:0000:0000:0000:0000:0000:0100","0000:0000:0000:0000:0000:0000:0000:0101","0000:0000:0000:0000:0000:0000:0000:0100"]

Carry crosses the low byte boundary and moves are cumulative.

Example 2

start = "0000:0000:0000:0000:ffff:ffff:ffff:ffff"moves = [1,-1]return = ["0000:0000:0000:0001:0000:0000:0000:0000","0000:0000:0000:0000:ffff:ffff:ffff:ffff"]

Carry and borrow cross the 64-bit midpoint.

Example 3

start = "abcd:0000:0000:0000:0000:0000:0000:0000"moves = []return = []

No moves produce no addresses.

Constraints

  • 0 <= moves.length <= 200000.
  • Every move is exactly -1 or 1.
  • start has eight four-digit lowercase hexadecimal groups.
  • Every intermediate address stays in the unsigned 128-bit range.

More OpenAI problems

  • Determine the Winner of Three-Card HandsPHONE SCREEN · Seen Nov 2026
  • Sparse Plant Infection SimulationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Light Source Hits: Sample, Compare, and FitPHONE SCREEN · Seen Nov 2026
All OpenAI interview questionsSee OpenAI hiring insights
Saved
class Solution {
    public String[] moveIPv6Addresses(String start, int[] moves) {
        // Write your solution here.
    }
}
Checking account…