Problem

Sort Real Number Strings

FULLTIMEPHONE SCREEN

You are given a list of strings. Each string represents a real number and may be positive, negative, or contain a decimal point.

Sort the strings by their numeric values without converting the full string to an arithmetic numeric data type.

Return the sorted list of original strings. If two strings represent the same numeric value, keep their original relative order.

Examples
01 · Example 1
numbers = ["10","-3.5","2.01","0"]
return = ["-3.5","0","2.01","10"]

The strings are ordered by numeric value: -3.5 < 0 < 2.01 < 10.

02 · Example 2
numbers = ["-1.25","-1.2","3","0.5","12.01"]
return = ["-1.25","-1.2","0.5","3","12.01"]

Among negative values, -1.25 is smaller than -1.2.

Constraints
  • numbers.length >= 1
  • Each string in numbers is a valid real number representation with an optional leading - sign and an optional decimal point.
More Walmart problems
drafts saved locally
public String[] sortRealNumberStrings(String[] numbers) {
  // write your code here
}
numbers["10","-3.5","2.01","0"]
expected["-3.5", "0", "2.01", "10"]
sign in to submit