#C14241. Flattening a Nested List

    ID: 43869 Type: Default 1000ms 256MiB

Flattening a Nested List

Flattening a Nested List

Problem Statement: Given a nested list (in JSON format), your task is to flatten it so that all elements from any level of nesting are extracted into a single list, preserving their order. The input can be an arbitrarily nested list containing numbers, strings, booleans, or null values. If the input is not a valid list (i.e. does not start with '['), output the error message: (\text{Input must be a list}).

For example, if the input is:
  [1, [2, [3, 4]], 5]
then the output should be:
  [1, 2, 3, 4, 5]

The flattened list must be printed in JSON array format (using standard JSON syntax).

inputFormat

Input is provided via standard input as a single line containing a nested list in JSON format. The list may be nested arbitrarily. If the input does not start with '[', print 'Input must be a list'.

outputFormat

Output the flattened list in JSON array format on standard output in a single line. If the input is invalid, output the error message exactly as specified.## sample

[]
[]