Smallest Value of the Rearranged Number
A medium-tier problem at 53% community acceptance, tagged with Math, Sorting. Reported in interviews at Cognizant and 0 others.
You're given digits and told to rearrange them into the smallest possible number. Sounds trivial, but there's a trap that catches half the people who see it. Cognizant has asked this, and it shows up in assessments testing whether you think before you code. The obvious greedy sort fails on a specific case that makes most candidates restart. StealthCoder surfaces the complete solution when you hit that wall during your live assessment.
Companies that ask "Smallest Value of the Rearranged Number"
Smallest Value of the Rearranged Number is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by an engineer at a top-10 tech company who can solve these problems cold but didn't want to trust himself in a 90-minute screen share.
Get StealthCoderThe trick is that sorting digits ascending doesn't always work. If your result starts with zero (like rearranging 3, 0, 30 into '0330' instead of '3033'), you need to handle the leading-zero case. The real pattern involves a custom comparator that compares concatenations: for two digits a and b, pick the order where ab < ba. This breaks the standard sort and reveals the correct minimal arrangement. Most candidates hardcode a zero-handling patch and miss the elegant comparator insight. When the problem hits live and you blank on why your greedy sort is wrong, StealthCoder runs invisibly and delivers the comparator solution in seconds.
Pattern tags
You know the problem.
Make sure you actually pass it.
Smallest Value of the Rearranged Number recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by an engineer at a top-10 tech company who can solve these problems cold but didn't want to trust himself in a 90-minute screen share. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Smallest Value of the Rearranged Number interview FAQ
Is this problem really asked at major companies?+
Yes. Cognizant has confirmed it in their hiring loop. With a 53% acceptance rate, it's not easy. The problem appears designed to catch people who skip the thinking phase and jump straight to Arrays.sort().
Why does sorting digits ascending not work?+
Because '3' + '30' sorted normally gives '3033', but '30' + '3' gives '3033' also. But '3' + '34' gives '334' while '34' + '3' gives '343'. You need to compare concatenations, not individual digit values.
What's the custom comparator trick?+
For two numbers a and b, compare the strings a+b versus b+a. If a+b is smaller, a should come first. This comparator naturally handles leading zeros and finds the globally minimal arrangement without special cases.
How does this relate to Sorting as a topic?+
It's a sorting problem, but not with the default comparator. You're implementing a domain-specific sort rule based on string concatenation. Standard Sorting knowledge isn't enough; you need to think about what 'smaller' means in context.
What happens if all digits are zero?+
The result should be '0', not '000...'. After rearranging with the comparator, check if the first character is zero. If so, return '0'. This is the edge case that flushes out incomplete solutions.
Want the actual problem statement? View "Smallest Value of the Rearranged Number" on LeetCode →