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.

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`.

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.

Validate an IPv6 address and return exactly 8 lowercase zero-padded hextets, or Invalid.

Constraints

  • Inputs are Python literals matching the function signature.
  • Return a deterministic exact-match value.

Examples

Input: ('2001:db8::1',)

Expected Output: '2001:0db8:0000:0000:0000:0000:0000:0001'

Explanation: Compressed example.

Input: ('::',)

Expected Output: '0000:0000:0000:0000:0000:0000:0000:0000'

Explanation: All zeros.

Hints

  1. Model object-style prompts as operation streams when needed.
  2. Handle empty and boundary cases before the main logic.

IPv6 Address Expander

mediumLiftoffSoftware Engineer

Validate an IPv6 address and return exactly 8 lowercase zero-padded hextets, or Invalid.

View full question (all parts)

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.

Examples

Example 1
Input
('2001:db8::1',)
Output
'2001:0db8:0000:0000:0000:0000:0000:0001'
Notes
Compressed example.
Example 2
Input
('::',)
Output
'0000:0000:0000:0000:0000:0000:0000:0000'
Notes
All zeros.

Constraints

  • •Inputs are Python literals matching the function signature.
  • •Return a deterministic exact-match value.

Comments (0)

No comments yet. Be the first to comment!

Submit your answer

Approved first answer today earns 30 XP
Bold⌘BItalic⌘IInline code⌘`Bullet listTab to nest (○ ■)Numbered listTab to nest (a. i.)QuoteCode block
Formatting help
Sample call
solution('2001:db8::1')
Language
Case 1
Input
('2001:db8::1',)
Expected
'2001:0db8:0000:0000:0000:0000:0000:0001'
Case 2
Input
('::',)
Expected
'0000:0000:0000:0000:0000:0000:0000:0000'

Browse More Questions