AniUI Academy

Array Flattening with Depth

easyArrays & Objects+150 XPFrontend AlgoArena

Nested array structures are common in JSON APIs. Implement a custom array flattener flatten(arr, depth).

What it has to do

  • Recursively flatten sub-arrays up to depth.
  • Default depth should be 1 if not specified.
  • Do not mutate original array.

Where it's been asked

  • Meta
  • Amazon
  • Google

From public interview reports — a problem very like this one has shown up in a round at these companies. Not an exhaustive list.

Try it yourself
Loading playground...

Ready to check it?

3 tests run against your code, right here in your browser. Sign in to claim the XP when you pass.

Need a nudge?

Reveal a conceptual hint or the reference solution. Both were written and reviewed with the problem — no runtime magic.

Discussion

Sign in to post
Sign in to join the conversation.Sign in

No comments yet. Be the first to say something.