You are given n lines of a simplified INI-style configuration file. Each line is exactly one of:
[name]key=value (the value may be empty, and never contains = or a newline)Any key/value assignment that appears before the first section header belongs to a virtual section named global. Section names and keys consist only of lowercase letters, digits, and underscores (so they never contain a .). If the same key is assigned more than once within the same section, the LAST assignment wins.
Produce the flattened output: for every distinct (section, key) pair that ends up with a value, print one line section.key=value. Sort these lines lexicographically (as plain strings) before printing.
Line 1: an integer n.
Lines 2..n+1: each a section header, a key/value assignment, or blank.
The sorted flattened lines, one per line. If there are no key/value assignments at all, print nothing.
[a-z0-9_]= or \nExample 1
Input
3 [db] host=localhost port=5432
Expected
db.host=localhost db.port=5432
Explanation
Both keys belong to section `db`; sorted alphabetically, `db.host` comes before `db.port`.
Example 2
Input
2 name=alice name=bob
Expected
global.name=bob
Explanation
Both assignments are pre-section (global) and share the key `name`; the later value `bob` wins, giving `global.name=bob`.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →