Flatten Nested Array

HardData EngineeringArraySorting

Description

Given an arbitrarily nested array of integers, return a single flat array containing every integer in left-to-right order, regardless of how deeply it is nested.

Examples

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

Every integer is collected in left-to-right order while the surrounding layers of nesting are discarded.

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

Every integer is collected in left-to-right order while the surrounding layers of nesting are discarded.

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

Every integer is collected in left-to-right order while the surrounding layers of nesting are discarded.

Constraints

  • nesting depth ≤ 100

Ready to solve this problem?

Practice solo and sharpen your skills for technical interviews.