PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Liftoff

Parse and expand an IPv6 address

Last updated: Mar 29, 2026

Quick Overview

This question evaluates proficiency in IPv6 address parsing, string validation, and canonicalization, testing understanding of hexadecimal hextets and the zero-compression (::) rule within the Coding & Algorithms domain.

  • medium
  • Liftoff
  • Coding & Algorithms
  • Software Engineer

Parse and expand an IPv6 address

Company: Liftoff

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

Implement an IPv6 address parser/normalizer. You are given a string `s` that may represent an IPv6 address using standard notation: - Up to 8 groups (“hextets”) separated by `:` - Each hextet is 1 to 4 hex digits (`0-9`, `a-f`, `A-F`) - A single `::` may appear at most once, representing one or more consecutive `0000` hextets (zero-compression) Task: 1. If `s` is a valid IPv6 address under the rules above, return its fully expanded canonical form: exactly 8 hextets, each as 4 lowercase hex digits, joined by `:`. 2. Otherwise return `"Invalid"`. Examples: - `"2001:db8::1"` → `"2001:0db8:0000:0000:0000:0000:0000:0001"` - `"::"` → `"0000:0000:0000:0000:0000:0000:0000:0000"` - `"1:2:3:4:5:6:7:8"` → `"0001:0002:0003:0004:0005:0006:0007:0008"` - `"1::2::3"` → `"Invalid"` (multiple `::`) - `"1:2:3:4:5:6:7:8:9"` → `"Invalid"` (too many hextets) Constraints: `|s| ≤ 100`.

Quick Answer: This question evaluates proficiency in IPv6 address parsing, string validation, and canonicalization, testing understanding of hexadecimal hextets and the zero-compression (::) rule within the Coding & Algorithms domain.

Related Interview Questions

  • Compute the Eddington number from ride distances - Liftoff (medium)
  • Find degrees of connection in a LinkedIn graph - Liftoff (medium)
  • Implement minimal RLE encode/decode with max run K - Liftoff (medium)
Liftoff logo
Liftoff
Feb 26, 2026, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
3
0

Implement an IPv6 address parser/normalizer.

You are given a string s that may represent an IPv6 address using standard notation:

  • Up to 8 groups (“hextets”) separated by :
  • Each hextet is 1 to 4 hex digits ( 0-9 , a-f , A-F )
  • A single :: may appear at most once, representing one or more consecutive 0000 hextets (zero-compression)

Task:

  1. If s is a valid IPv6 address under the rules above, return its fully expanded canonical form: exactly 8 hextets, each as 4 lowercase hex digits, joined by : .
  2. Otherwise return "Invalid" .

Examples:

  • "2001:db8::1" → "2001:0db8:0000:0000:0000:0000:0000:0001"
  • "::" → "0000:0000:0000:0000:0000:0000:0000:0000"
  • "1:2:3:4:5:6:7:8" → "0001:0002:0003:0004:0005:0006:0007:0008"
  • "1::2::3" → "Invalid" (multiple :: )
  • "1:2:3:4:5:6:7:8:9" → "Invalid" (too many hextets)

Constraints: |s| ≤ 100.

Submit Your Answer

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Liftoff•More Software Engineer•Liftoff Software Engineer•Liftoff Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.