Diff Two Hierarchical Switch Running Configurations

Last updated: November 29, 2026

Quick Overview

Parse two indentation-based switch configurations (running and candidate) into trees and print a hierarchical diff showing added and removed lines with their parent sections as context.

Arista Networks
Coding & Algorithms
Software Engineer
Arista Networks
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

0

0 solved


Parse two indentation-based switch configurations (running and candidate) into trees and print a hierarchical diff showing added and removed lines with their parent sections as context.

EOS config sessions and CloudVision change control both show an operator exactly what will change before it is committed. The interviewer checks tree parsing from indentation, recursive comparison, and output an operator can read.

What the Interviewer Expects
  • Parse indentation into a tree with a stack of (indent, node)
  • Ignore blank lines and `!` separators
  • Recursively compare children by line text
  • Print a parent as context only when something below it changed
  • Emit the whole subtree when a section is added or removed
Key Topics to Cover
tree parsing
recursion
diff
configuration management
stack
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
  • How would you turn the diff into the minimal CLI commands to apply (including `no` forms)?
  • Some sections are order-sensitive (ACL entries, route-map sequences). How do you diff those?
  • How would you treat `description spine1` replacing `description uplink` as a modification rather than a remove plus add?
  • How do you handle commands that the device normalizes, such as defaults that are hidden?
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

Config lines are nested by leading spaces (EOS uses 3). Sibling lines are unique within a section and order does not matter for this version. Output lines start with +, - or a space for unchanged ...

High-Level Design

Parse each config into a nested dict {line: children}. A stack holds (indent, node); for each line, pop while the top's indent is at least the current indent, then attach to the top. Diffing two t...


Submit Your Answer
Markdown supported

Related Questions