2727. Is Object Empty LeetCode Solution

In this guide, you will get 2727. Is Object Empty LeetCode Solution with the best time and space complexity. The solution to Is Object Empty problem is provided in various programming languages like C++, Java, and Python. This will be helpful for you if you are preparing for placements, hackathons, interviews, or practice purposes. The solutions provided here are very easy to follow and include detailed explanations.

Table of Contents

  1. Problem Statement
  2. Complexity Analysis
  3. Is Object Empty solution in C++
  4. Is Object Empty solution in Java
  5. Is Object Empty solution in Python
  6. Additional Resources
2727. Is Object Empty LeetCode Solution image

Problem Statement of Is Object Empty

Given an object or an array, return if it is empty.

An empty object contains no key-value pairs.
An empty array contains no elements.

You may assume the object or array is the output of JSON.parse.

Example 1:

Input: obj = {“x”: 5, “y”: 42}
Output: false
Explanation: The object has 2 key-value pairs so it is not empty.

Example 2:

Input: obj = {}
Output: true
Explanation: The object doesn’t have any key-value pairs so it is empty.

Example 3:

Input: obj = [null, false, 0]
Output: false
Explanation: The array has 3 elements so it is not empty.

Constraints:

obj is a valid JSON object or array
2 <= JSON.stringify(obj).length <= 105

Can you solve it in O(1) time?

Complexity Analysis

  • Time Complexity: Google AdSense
  • Space Complexity: Google Analytics

2727. Is Object Empty LeetCode Solution in C++

type JSONValue =
  | null
  | boolean
  | number
  | string
  | JSONValue[]
  | { [key: string]: JSONValue };
type Obj = Record<string, JSONValue> | JSONValue[];

function isEmpty(obj: Obj): boolean {
  if (Array.isArray(obj)) {
    return obj.length === 0;
  }
  return Object.keys(obj).length === 0;
}
/* code provided by PROGIEZ */

2727. Is Object Empty LeetCode Solution in Java

N/A
// code provided by PROGIEZ

2727. Is Object Empty LeetCode Solution in Python

N/A
# code by PROGIEZ

Additional Resources

See also  1678. Goal Parser Interpretation LeetCode Solution

Happy Coding! Keep following PROGIEZ for more updates and solutions.