#C11445. Flatten a Nested List Iterator

    ID: 40762 Type: Default 1000ms 256MiB

Flatten a Nested List Iterator

Flatten a Nested List Iterator

You are given a nested list of integers in JSON format. Your task is to flatten the list by performing a depth-first search (DFS) and output the resulting sequence of integers.

The nested list is represented as a JSON array where each element can either be an integer or another JSON array. The order of the output must follow a DFS order.

Example 1:
Input: [[1, 1], 2, [1, [4, [6]], 1]]
Output: 1 1 2 1 4 6 1

Example 2:
Input: [1,2,3]
Output: 1 2 3

Note: The input is provided via standard input (stdin) as a single line, and the output should be printed to standard output (stdout) as a space-separated list of integers.

inputFormat

A single line containing a JSON array that represents a nested list of integers. Each element is either an integer or another nested list.

outputFormat

A single line containing the flattened sequence of integers, printed in order and separated by a single space.## sample

[[1, 1], 2, [1, [4, [6]], 1]]
1 1 2 1 4 6 1