Reported January 2026
Walmartsorting

Sort Real Number Strings

Reported by candidates from Walmart's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Walmart OA. Under 2s to a working solution.
Founder's read

The mistake that sinks a first attempt on Walmart's Sort Real Number Strings is calling a plain string sort and hoping it works. This one was reported in January 2026, and it's a sorting problem with a catch: you can't convert the full string to a numeric type. So "10" beats "2.01" lexically and negatives flip the order. You need a custom comparator that reads sign, integer part, and fractional part separately. If your head goes blank on the comparator, StealthCoder runs invisibly during the live OA and gives you a working solution as a safety net.

The problem

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.

Function
sortRealNumberStrings(numbers: String[]) → String[]

Examples
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.
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.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is a comparator built from parsed pieces. Split each string into sign, integer digits, and fractional digits. Strip leading zeros from the integer part and trailing zeros from the fraction, and treat "-0" or "-0.0" as zero. Compare signs first. For two positives, a longer integer part is bigger, and if lengths match, compare lexically, then compare the fractions lexically. For two negatives, flip the result. The pitfall is the fractional part: "1.2" versus "1.25" must compare digit by digit with padding, not by length. Use a stable sort, since equal values must keep their original order. Most built-in sorts are stable, but confirm yours is. Pitfalls also include strings like ".5" or "+3" if the input allows them. Handle them defensively. If the comparator logic slips under pressure, StealthCoder is the hedge on the live OA.

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

If this hits your live OA

You can drill Sort Real Number Strings cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. If you're reading this with an OA window open, you're who this was built for.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Walmart's OA.

Walmart reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Sort Real Number Strings FAQ

What's the trick in Sort Real Number Strings?+

Write a custom comparator that never converts the whole string to a number. Parse sign, integer part, and fractional part as strings. Compare signs, then integer length, then integer digits, then fraction digits. Reverse the result for negatives. Plug it into a stable sort.

Why does plain string sorting fail here?+

Lexical order compares character by character. "10" sorts before "2.01" because '1' is less than '2'. The minus sign also breaks things, since -3.5 and -1.2 would order wrong. Numeric value needs sign-aware, length-aware comparison, not character order.

How do I handle equal values like 1.50 and 1.5?+

Normalize when comparing: trim trailing zeros from the fraction and leading zeros from the integer part. If the comparator returns equal, rely on a stable sort so the original relative order is kept. Don't modify the strings you return.

How do I compare fractional parts correctly?+

Compare digit by digit from the left, padding the shorter fraction with zeros. So 0.5 versus 0.25 compares 5 against 2 first and 0.5 wins. Never compare fraction lengths. Longer doesn't mean bigger after the decimal point.

How do I prepare for this in 48 hours?+

Write the comparator once from scratch and test it on negatives, zeros, and mixed decimals. Check -0, equal values with trailing zeros, and a mix of integers and decimals. Then confirm your language's sort is stable. That covers almost every way this problem fails.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Walmart.

OA at Walmart?
Invisible during screen share
Get it