#K85952. Flatten Nested List

    ID: 36755 Type: Default 1000ms 256MiB

Flatten Nested List

Flatten Nested List

You are given a nested list containing integers and/or strings. Your task is to flatten the nested list into a single-level list while maintaining the order of appearance.

For example, given the list:

[1, 2, [3, 4, [5]]]

the flattened version is:

[1, 2, 3, 4, 5]

The flattening process can be formally defined as follows. Let \( L \) be a list. Then the flattening function \( f(L) \) is defined recursively by:

\( f(x) = [x] \)  if \( x \) is not a list,
\( f(L) = \bigoplus_{x \in L} f(x) \) if \( L \) is a list,

where \( \bigoplus \) denotes the concatenation of lists.

inputFormat

The input is given via stdin as a single line containing a valid JSON array that represents a nested list. The nested list may contain integers and/or strings. You can assume the JSON input is well-formed.

outputFormat

Output via stdout the flattened list as a JSON array. The output should preserve the order of elements as they appear in the original nested list.

## sample
[1, 2, [3, 4, [5]]]
[1, 2, 3, 4, 5]