Drop Nulls

EasyData EngineeringArraySorting

Description

Given an array that may contain null entries, return a new array with every null removed, preserving the order of the remaining values.

Examples

Input:[1,null,2,null,3]
Output:[1,2,3]
Explanation:

Every missing entry is removed, leaving only the present values in their original order.

Input:[null,null]
Output:[]
Explanation:

Every missing entry is removed, leaving only the present values in their original order.

Input:[1,2,3]
Output:[1,2,3]
Explanation:

Every missing entry is removed, leaving only the present values in their original order.

Constraints

  • 0 ≤ array length ≤ 10⁴

Ready to solve this problem?

Practice solo and sharpen your skills for technical interviews.