Code
Loading editor...
Tap Analyze to see visualization
Click Analyze to visualize
See step-by-step execution, variables, and output
Variables
Run code to see variables
Output
Console output will appear here
Click Analyze to visualize
See step-by-step execution, variables, and output
Run code to see variables
Console output will appear here
Convert numbers to strings. Sort with a custom comparator that compares the concatenation a+b vs b+a. If a+b is larger, a should come first. Join the sorted strings. Handle edge case where all numbers are 0.
The comparator defines a total ordering: if ab > ba, then a should precede b. This greedy choice is provably optimal because it maximizes the contribution of each number in its position. The edge case check for leading zeros handles inputs like [0, 0].
Updated Feb 2026