#C14218. Flatten a Nested List

    ID: 43843 Type: Default 1000ms 256MiB

Flatten a Nested List

Flatten a Nested List

You are given a nested list of integers represented in JSON format. This list may contain integers or other lists which themselves can contain further integers and lists, thus forming an arbitrarily nested structure. Your task is to flatten this list into a single list of integers, preserving the order of appearance.

For instance, if the input is [1, [2, 3], [4, [5, 6]], 7], then the flattened list should be [1, 2, 3, 4, 5, 6, 7].

The input will be provided on stdin as a single line string representing the nested list in valid JSON format. The output should be printed to stdout as the flattened list elements separated by a single space.

Note: You may assume that all integers are valid and the structure is well-formed.

inputFormat

Input is read from stdin. A single line contains a valid JSON representation of a nested list of integers. For example:

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

outputFormat

Output to stdout the flattened list of integers separated by a single space. For the above example, the output should be:

1 2 3 4 5 6 7## sample

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