#C12362. Flatten a Nested List
Flatten a Nested List
Flatten a Nested List
Your task is to flatten a nested list into a single list. The nested list may contain integers, strings, or other nested lists. The flattened list should contain all the elements in the same order as they appear in the original nested list.
For example, given the input:
[1, [2, [3, 4], 5], 6, [7, [8, [9], 10], 11], 12, []]
the output should be:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
Remember to read input from standard input (stdin) and write your result to standard output (stdout). All lists are given in valid JSON array format.
inputFormat
The input consists of a single line, containing a JSON formatted array which represents a nested list. The list may consist of integers, strings (enclosed in double quotes), and nested lists.
Example:
[1, [2, [3, 4], 5], 6]
outputFormat
Output the flattened list as a JSON array. The elements should preserve their original order.
Example:
[1, 2, 3, 4, 5, 6]## sample
[1, [2, [3, 4], 5], 6, [7, [8, [9], 10], 11], 12, []]
[1,2,3,4,5,6,7,8,9,10,11,12]