A warehouse logging system stores every cargo manifest node as a single JSON value. A node is either a leaf (a number, a string, a boolean, or null), a list node (a JSON array of sub-manifests), or a map node (a JSON object whose keys name compartments and whose values are sub-manifests).
You are given exactly one manifest node. Determine whether it is directly empty: a map node with zero keys, or a list node with zero elements. A leaf is never considered empty. A map or list node that holds at least one key or element is not empty, even if every value nested inside it is itself empty — only the outermost node's own key/element count matters.
A single line containing one syntactically valid JSON value. The value may contain nested objects, arrays, strings, numbers, booleans, and null, and may include arbitrary spaces immediately inside brackets or around punctuation (e.g. { } or [ 1, 2 ]).
Print true if the given node is directly an empty object or an empty array; otherwise print false.
Example 1
Input
{}Expected
true
Explanation
The node is a JSON object with zero keys, so it is directly empty and the answer is true.
Example 2
Input
{"a": {}, "b": [1,2,3]}Expected
false
Explanation
The top-level node is an object with two keys, "a" and "b", so it holds content and is not empty. This is true even though the value under "a" is itself an empty object — only the outermost node's own key count is checked, so the answer is false.
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 →