MediumNo. 2705
Compact Object — LeetCode 2705 Python Solution
- Topics
- JavaScript
- Reading time
- 2 min
- Source
- leetcode.com
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
| No. | Problem | Difficulty |
|---|---|---|
| 0057 | Insert Interval | Medium |
| 0192 | Word Frequency | Medium |
| 0193 | Valid Phone Numbers | Easy |
| 0194 | Transpose File | Medium |
| 0195 | Tenth Line | Easy |
| 0228 | Summary Ranges | Easy |
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.