Resolve Inherited Server Configuration
Updated
Problem statement
Parse a valid server configuration file supplied as its complete text lines. A header [server] starts a base section. A header [child:base] starts a section that inherits from exactly one base. A property line has the exact form key = value, with one space on each side of the equals sign. Empty lines may separate sections but are not required.
A child inherits all properties from its base, including properties inherited from earlier ancestors. Its own property values override inherited values with the same key. Do not modify a base when resolving its child. Bases may be defined later in the file, and inheritance may have several levels.
Return the resolved file as text lines. Sort sections by name and properties within each section by key. Print a resolved header as [server], then its key = value lines. For this exercise, assume case-sensitive ASCII sorting, exactly one empty line between output sections, and no leading or trailing empty line.
For this exercise, assume section names and keys start with an ASCII letter or underscore and continue with ASCII letters, digits, or underscores. Values are nonempty tokens containing ASCII letters, digits, underscores, periods, or hyphens. Each section is declared once, each local key is assigned once, every named base exists, and inheritance is acyclic. An empty input returns an empty array.
Function
resolveConfiguration(lines: String[]) → String[]Examples
Example 1
lines = ["[base_server]","ram = 16G","disk = 15G","","[review_console:admin_console]","","[admin_console:base_server]","ram = 32G","owner = root"]return = ["[admin_console]","disk = 15G","owner = root","ram = 32G","","[base_server]","disk = 15G","ram = 16G","","[review_console]","disk = 15G","owner = root","ram = 32G"]base_server keeps disk = 15G and ram = 16G. admin_console inherits disk, changes ram to 32G, and adds owner. review_console inherits that complete result even though admin_console is defined later. The sorted output keeps the literal disk value 15G.
Example 2
lines = ["[staging_server:base_server]","ram = 8G","envname = Staging","","[dev_server:staging_server]","envname = Dev","","[test_server:dev_server]","disk = 4G","","[base_server]","ram = 16G","disk = 15G","","[qa_server:base_server]","ram = 4G"]return = ["[base_server]","disk = 15G","ram = 16G","","[dev_server]","disk = 15G","envname = Dev","ram = 8G","","[qa_server]","disk = 15G","ram = 4G","","[staging_server]","disk = 15G","envname = Staging","ram = 8G","","[test_server]","disk = 4G","envname = Dev","ram = 8G"]staging_server changes ram to 8G and adds envname. dev_server changes only envname to Dev. test_server changes disk to 4G and inherits Dev and 8G through both levels. qa_server independently inherits disk = 15G and changes ram to 4G. The five sections and each section's keys are sorted.
Constraints
- For this exercise, assume
0 <= lines.length <= 40and each line has 0 to 63 characters. - There are at most 8 sections and at most 24 property assignments in the file. Section names, keys, and values each have 1 to 30 characters.
- Each nonempty line is exactly a header [server], a single-base header [child:base], or a property key = value. Properties follow a section header, and no spaces occur except the two spaces surrounding the assignment equals sign.
- Every section and local key is unique within its scope. Every base is declared, and the inheritance graph is acyclic.
More Intuit Online Assessment questions
- Employee Promotion OpportunitiesOA · Seen Oct 2026
- Next Pascal Row CoefficientOA · Seen Oct 2026
- Parse Router LogsOA · Seen Oct 2026
- Longest Repeated Letter Block with Adjacent SwapsOA · Seen Oct 2026
- Maximum Square-Free DivisorOA · Seen Oct 2026
- Two Tribes from Taller-Person CountsOA · Seen Oct 2026
- Shortest Path from an Encoded GraphOA · Seen Sep 2026
- Oldest and Youngest EmployeesOA · Seen Sep 2026
- Pressure-Isolation Shutdown OrderOA · Seen Sep 2026
- Submask Sum QueriesOA · Seen Sep 2026
Similar questions at other companies
- Filesystem Hash TreeCursor · PHONE SCREEN · ONSITE INTERVIEWCursor interview questions
- Decode Words with Anagram KeysCresta · OACresta interview questions
- Longest String ChainVisa · OAVisa interview questions
- Frequently Bought TogetherAmazon · OA
- Build and Render an Organization Role TreeStripe · OAStripe interview questions
- Maximize Palindromic WordsSquarepoint Capital · OASquarepoint Capital interview questions
- Aggregate Paginated Project Run RecordsReplit · OA
- Count User Logins 🌿 (Singapore)PayPal · OAPayPal interview questions
- Largest Lexicographical Substring 🌿Google · OAGoogle interview questions
- Count Distinct Message MentionsZipRecruiter · OAZipRecruiter interview questions