Sort Paragraphs by Leading Version
Updated
Problem statement
Each paragraph begins with a version token followed by a space and arbitrary text. A version token contains one or more non-negative decimal components separated by either . or ,; separators may be mixed.
Sort paragraphs by numeric component sequence. Compare components left to right, treating missing trailing components as zero. If normalized versions are equal, preserve original input order.
Return the complete original paragraph strings in sorted order.
Function
sortVersionedParagraphs(paragraphs: String[]) → String[]Examples
Example 1
paragraphs = ["2.02.11 second","1,11,03 first","2.2.3 middle"]return = ["1,11,03 first","2.2.3 middle","2.02.11 second"]Numeric versions are [1,11,3], [2,2,3], and [2,2,11].
Example 2
paragraphs = ["1.0 alpha","1 beta","1.0.0 gamma"]return = ["1.0 alpha","1 beta","1.0.0 gamma"]All normalized versions are equal, so stable input order is preserved.
Example 3
paragraphs = []return = []No paragraphs remain empty.
Constraints
0 <= paragraphs.length <= 100000.- Each paragraph is nonempty and begins with a valid version token and one space.
- Each version has at most 20 components, each in
[0,10^9].
More Google Phone Screen questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Periodic-Color Binary Forest RootsPHONE SCREEN · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
- Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
- Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
- Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Rank Word-Translation Hints from Sentence TranslationsDuolingo · PHONE SCREEN · ONSITE INTERVIEW
- Top K Movies by Play Count from CSV DataTubi · PHONE SCREEN
- Insert an Employee into an Organization HierarchyWaymo · PHONE SCREEN
- Common Words Across FilesMeta · PHONE SCREEN
- Brazilian Receivables Part 3 — Partial ContractsStripe · PHONE SCREEN
- Summarize Server Healthcheck LogsNVIDIA · PHONE SCREEN
- Find Valid IP AddressesVerkada · PHONE SCREEN
- Response Time Stats by URL PatternGusto · ONSITE INTERVIEW
- Transform Dotted Keys into a Nested MapProofpoint · ONSITE INTERVIEW
- Serialize and Deserialize a String Key-Value StoreByteDance · ONSITE INTERVIEW