Open in app
Home
Notifications
Lists
Stories

Write
Ranga Dewasinghe
Ranga Dewasinghe

Home

Mar 1, 2019

Flatten Arrays using C#

Here I came up with a common interview question that you might get in an interview. So the question goes as follows, Write a function, that when given a multi-level array, flattens it into a 1D array. Sample Input — [1, 2, [3, [4, 5]], 6] Sample Output — [1, 2, 3, 4, 5, 6] One of the possible ways that we can use to solve this is a recursive approach because we really don't know how many levels of nested arrays are going to be there. So, I came up with the following solution using LINQ.

Csharp

1 min read

Ranga Dewasinghe

Ranga Dewasinghe

An Enthusiast Programmer

Following
  • PCMag

    PCMag

  • ReadWrite

    ReadWrite

  • Intel

    Intel

  • Mindfire Solutions

    Mindfire Solutions

  • UN Development Programme

    UN Development Programme

Help

Status

Writers

Blog

Careers

Privacy

Terms

About

Knowable