Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Flatten Nested Array Structure

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Flatten Nested Array Structure. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Given a nested array arr, return a new flat array containing all non-array elements in left-to-right order. Elements may be nested to arbitrary depth, and empty nested arrays should contribute nothing to the result.

Constraints

  • 0 <= len(arr) <= 10^4
  • Nesting depth is between 0 and 10^3
  • Elements are either integers or arrays containing the same kinds of values
  • Preserve the original left-to-right traversal order

Function Signature

def flatten_array(arr):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output