Compact Object — LeetCode 2705 Python Solution
MediumJavaScript
- Problem
- #2705
- 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
| Measure | Complexity |
|---|---|
| Time | O(n) |
| Space | O(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.