Normalize Overlapping VLAN Range Lists in Switch Config

Last updated: November 29, 2026

Quick Overview

Given a trunk allowed-VLAN string such as "10-20,15,30-25,5", return the canonical compressed form with sorted, merged, non-overlapping ranges, and reject VLAN IDs outside 1 to 4094.

Arista Networks
Coding & Algorithms
Software Engineer
Arista Networks
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


Given a trunk allowed-VLAN string such as "10-20,15,30-25,5", return the canonical compressed form with sorted, merged, non-overlapping ranges, and reject VLAN IDs outside 1 to 4094.

EOS CLI and CloudVision both have to canonicalize VLAN lists so that two configs that mean the same thing compare equal. This screen checks clean parsing, range merging, and attention to the valid 802.1Q range.

What the Interviewer Expects
  • Parse single IDs and ranges, tolerating reversed ranges
  • Validate VLAN IDs against 1 to 4094
  • Merge adjacent as well as overlapping ranges (10-20 and 21 become 10-21)
  • Output single IDs without a dash
  • Discuss set versus interval-merge trade-offs
Key Topics to Cover
string parsing
interval merging
VLAN
input validation
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Rewrite it with interval merging so the cost does not depend on range width.
  • Implement `add` and `remove` of a VLAN range against an existing canonical string.
  • How would you diff two VLAN lists to produce `switchport trunk allowed vlan add/remove` commands?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: comma-separated tokens, each a VLAN ID or lo-hi. Output: sorted, merged ranges joined by commas, adjacent IDs merged. Invalid IDs raise ValueError. Empty input returns an empty string....

High-Level Design

The VLAN space is only 4094 IDs, so expanding into a set is simple and bounded. Sort the set and sweep, starting a new run whenever the next ID is not prev + 1. An interval-merge variant (sort `(lo,...


Submit Your Answer
Markdown supported

Related Questions