As reported: Walmart Senior Software Engineer round 1 (2025): given a list of strings, each holding a real number (positive, negative or decimal), sort them without converting them to a numeric type.
Return the strings sorted by numeric value, smallest first. Compare them as strings only — the values can be longer than any built-in numeric type.
Example 1
["3.14", "-2", "10", "0.5", "-2.75", "0"] -> ["-2.75", "-2", "0", "0.5", "3.14", "10"]
Example 2
["-0.001", "-0.01", "100", "99.99", "1"] -> ["-0.01", "-0.001", "1", "99.99", "100"]
Clarifications
- Each string is
-?+ an integer part + optionally.and a fractional part. The integer part has no leading zeros (it is"0"when the value is below 1 in magnitude); the fractional part has no trailing zeros and is never empty after a.; zero is written"0", never"-0". - So two strings are equal in value only when they are identical; duplicates may appear.
Constraints: 1 ≤ n ≤ 2·10^4; each string has at most 52 characters.
Code runner format: one line with the JSON array of strings. Implement sortNumbers(nums); the harness prints the sorted array.