#K10981. Flatten and Square Nested List
Flatten and Square Nested List
Flatten and Square Nested List
You are given a nested list of integers. The list may contain integers or further nested lists. Your task is to flatten the list and then square each integer. For example, if the input is [[1,2,3],[4,5],[6]]
, after flattening the list becomes [1,2,3,4,5,6]
and after squaring each number the result is [1,4,9,16,25,36]
.
Note that the nested structure can be arbitrarily deep. You need to implement a solution that reads the input from standard input (stdin) and outputs the result to standard output (stdout). The output should be the squared numbers printed in order, separated by a single space. If the resulting list is empty, output nothing.
Input Format: A single line containing a valid JSON array representing the nested list.
Output Format: A single line containing the squared numbers separated by a space.
inputFormat
The input is provided as a single line from stdin containing a JSON representation of a nested list. For example:
[ [1, 2, 3], [4, 5], [6] ]
outputFormat
The output should be a single line to stdout with the squared integers, separated by a single space. For the example above, the output should be:
1 4 9 16 25 36## sample
[[1, 2, 3], [4, 5], [6]]
1 4 9 16 25 36