FastPrepParse and Sort Integer Data
Problems/Parse and Sort Integer Data

Parse and Sort Integer Data

Legora logoLegora● EasyFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Legora phone screen as an easy task of parsing data and sorting it. We chose the format of the integer list, the number order, what counts as valid, and what to do with empty input. Our version is about 70% the same as the reported question.

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 2000 integers.
  • Every parsed integer lies between -10^9 and 10^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 10 decimal 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
See Legora hiring insights
Saved
class Solution {
    public int[] parseAndSort(String data) {
        // Write your code here.
    }
}
Checking account…