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
November 29, 20260
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
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- 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 ProblemsSample 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,...