Dsa
Recursion
Hard
Nested JSON Keys Count
Given a nested JSON object, count the total number of keys present at all levels. You must consider that some keys may contain objects as values which, in turn, can contain more keys. The input will be provided as a string representation of a JSON object. You should output a single integer indicating the total count of unique keys encountered.
Input Format:
- A single line containing a string representation of a JSON object.
Output Format:
- A single integer representing the total count of unique keys.
Example:
Input:
{"a": 1, "b": {"c": 2, "a": 3}, "d": {"e": {"f": 4}}}
Output:
5
Key concepts
recursionjsoncounting
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now