MediumNo. 2705

Compact Object — LeetCode 2705 Python Solution

Topics
JavaScript
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

Time
O(n)
Space · auxiliary
O(n)

Related problems

Related problems
No.ProblemDifficulty
0057Insert IntervalMedium
0192Word FrequencyMedium
0193Valid Phone NumbersEasy
0194Transpose FileMedium
0195Tenth LineEasy
0228Summary RangesEasy

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.

Free to download. Check it runs on your machine, then pick a plan.