#C13231. Extract and Sort Numbers
Extract and Sort Numbers
Extract and Sort Numbers
You are given a nested list (JSON array) which can contain numbers (both integers and floating‐point values), strings, and other non‐numeric elements. Your task is to extract all the numeric values from this nested list, regardless of the level of nesting, and output them sorted in ascending order.
Formally, if the input array is denoted as \(A\), you need to implement an algorithm that finds all \(x \in A\) (possibly nested) such that \(x\) is a number, and then output the sorted list of these numbers.
Note: The input is provided as a single line representing a valid JSON array. The output should be a list (in JSON format) of the numeric values sorted in ascending order.
inputFormat
The input consists of a single line containing a JSON array. This array may contain nested arrays, strings, objects, nulls, etc. You only need to extract the numbers (integers and floating-point numbers).
For example:
[3, "hello", [9.8, "world", [7, [6, 4], 8, "test"], 5.2], "example", 0, [1.5, "code", [3.14, [2.71]]]]
outputFormat
Output a single line representing the resulting list (in JSON array format) of all the numeric values from the input sorted in ascending order.
For example, for the above input, the expected output is:
[0, 1.5, 2.71, 3, 3.14, 4, 5.2, 6, 7, 8, 9.8]## sample
[3, 1.5, -4.2, 22]
[-4.2, 1.5, 3, 22]