Skip to main content
CodeOath
← All problems

Problem

Flatten Array One Level

Medium
  • arrays

Remove one level of nesting from arr. Every element that is itself an array/list is replaced by the elements inside it. Anything nested deeper than that stays exactly as it is.

Example 1
Input
arr = [1, [2, 3], [4]]
Output
[1, 2, 3, 4]
Explanation

[2, 3] and [4] are each opened once, and their elements take their place.

Example 2
Input
arr = [[1, [2, 3]], 4]
Output
[1, [2, 3], 4]
Explanation

the outer list is opened, but [2, 3] sits one level deeper, so it stays a list.

Example 3
Input
arr = [1, 2, 3]
Output
[1, 2, 3]
Explanation

no element is a list, so nothing changes.

Tab indents. Press Esc, then Tab to leave the editor.

Run your code to see every test here. Nothing is submitted or recorded.