Parse and Sort Integer Data
Updated
Problem statement
Read the integers from data and return them sorted from smallest to largest.
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. Sort by numeric value, not by the order of the numbers as text.
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.
Similar questions at other companies
- Shared Courses for Every Pair of StudentsCrunchyroll · PHONE SCREENCrunchyroll interview questions
- Convert an Entry List to a MapEPAM · PHONE SCREENEPAM interview questions
- Remove Later Anagrams From a ListBloomberg LP · PHONE SCREENBloomberg LP interview questions
- Employees With Shared InterestsPalantir · PHONE SCREENPalantir interview questions
- Find All Word Occurrences in TextSentry · PHONE SCREENSentry interview questions
- Folder Snapshot DiffAirbnb · PHONE SCREENAirbnb interview questions
- Anagrams of a Word in a Word ListZillow · PHONE SCREEN · ONSITE INTERVIEWZillow interview questions
- Rank Word-Translation Hints from Sentence TranslationsDuolingo · PHONE SCREEN · ONSITE INTERVIEWDuolingo interview questions
- Merge Weekday and Time IntervalsNextdoor · PHONE SCREENNextdoor interview questions
- Group AnagramsWorkday · PHONE SCREEN