#C7477. Flattening a Nested List of Integers

    ID: 51352 Type: Default 1000ms 256MiB

Flattening a Nested List of Integers

Flattening a Nested List of Integers

You are given a nested list of integers which may contain other lists of integers as elements. Your task is to flatten this list, i.e. convert it into a single list of integers while preserving the order as they appear in a recursive traversal.

Formally, if the list is represented as ( L ), then its flattened version is defined recursively as follows:
( flatten(L) = \begin{cases} [L] & \text{if } L \text{ is an integer} \ flatten(L[0]) \ \Vert \ flatten(L[1:]) & \text{if } L \text{ is a non-empty list} \end{cases} )

Input Format:

A single line containing a JSON array representing the nested list of integers.

Output Format:

Print the flattened list as a sequence of integers separated by a single space. If the resulting list is empty, print nothing.

inputFormat

A single line in JSON format representing a nested list of integers. For example: [1, [2, [3, 4]]].

outputFormat

The flattened list of integers in the order they are encountered, printed as space-separated values on a single line. For an empty list, output nothing.## sample

[1, 2, 3]
1 2 3

</p>