Convert Nested Map to Dot-Notation Keys
Difficulty: Medium · Topics: Recursion, Map, Conversion
Difficulty: Medium | Tags: Recursion, Map, Conversion
Description
Given a nested Map, flatten it into a single-level map where keys use dot-notation to represent hierarchy.
Implement:
flattenMap(map) → Map<String, Object>
Examples
Example 1:
Input: {"db": {"host": "localhost", "port": 5432, "options": {"ssl": true}}}
Output: {"db.host": "localhost", "db.port": 5432, "db.options.ssl": true}
Example 2:
Input: {"a": {"b": {"c": {"d": 1}}}}
Output: {"a.b.c.d": 1}
Constraints
- Keys contain only alphanumeric characters and underscores.
- Nesting depth ≤ 10.
- No
nullkeys.