Amazon Interview Question

Sort a mathematical string in fastest way possible with best space complexity.