Parse and Sort Integer Data
Problem statement
Parse the text data into integer values and return those values in nondecreasing numeric order.
For this exercise, assume the input is a comma-separated list of signed decimal integers. Each integer may have an optional leading + or -, and surrounding ASCII spaces, tabs, carriage returns, or newlines. Preserve every occurrence, including duplicates. An empty or whitespace-only input represents an empty list.
All nonempty inputs are valid: each comma separates two nonempty integer fields. Numeric order differs from lexicographic text order.
Function
parseAndSort(data: String) → int[]Examples
Example 1
data = "10, 2, -3, 2"return = [-3,2,2,10]Numeric sorting places 10 after 2 and preserves both occurrences of 2.
Example 2
data = " "return = []Whitespace-only text represents an empty list.
Constraints
0 <= data.length <= 30000.- The parsed list contains at most
2000integers. - Every parsed integer lies between
-10^9and10^9, inclusive. - Every nonempty field is a valid signed base-ten integer; no internal whitespace occurs within its sign or digits.
- Each integer field has at most
10decimal digits, excluding its optional sign and surrounding whitespace.