Compact Object — LeetCode 2705 Python Solution

MediumJavaScript
Problem
#2705
Reading time
2 min

The problem

Given an object or array obj, return a compact object. A compact object is the same as the original object, except with keys containing falsy values removed.

Example

Input
obj = [null, 0, false, 1]
Output
[1]
Explanation
All falsy values have been removed from the array.

Complexity

MeasureComplexity
TimeO(n)
SpaceO(n) auxiliary

Related problems

Frequently asked questions

How hard is LeetCode 2705. Compact Object?
LeetCode 2705. Compact Object is rated Medium on LeetCode.
What is the time complexity of LeetCode 2705. Compact Object?
The Python solution on this page runs in O(n).
What is the space complexity of LeetCode 2705. Compact Object?
The Python solution on this page uses O(n) auxiliary space.
What topics does LeetCode 2705. Compact Object cover?
LeetCode 2705. Compact Object is tagged JavaScript on LeetCode.

Stuck on problems like this in a live interview?

Stealth Interview is a desktop app for macOS and Windows. It reads the problem off your screen and returns a working solution with a step-by-step explanation and its time and space complexity — invisible to screen sharing.

Get Stealth Interview