Sorting integers by their digits (Level 3) - MATLAB Cody - MATLAB Central

Problem 42815. Sorting integers by their digits (Level 3)

  • Created by HH
Difficulty:Rate

This is the next step up from Problem 42811.

Given a vector, v, of real numbers (negative or positive), return a vector, w, by sorting v in ascending order, such that primary sorting is done by the first digit (representing the largest value), secondary sorting by the second digit (next largest value), and so on.

Example:

v = [14.38 80.42 3.14 268 -14.38 210 1 80.44];

w = [1 -14.38 14.38 210 268 3.14 80.42 80.44];

As shown above, in cases of multiple numbers starting with the same digits, such as 1 and 14.38, shorter numbers take precedence.

Negative numbers take precedence over positive numbers.

Solution Stats

71.43% Correct | 28.57% Incorrect
Last Solution submitted on Jun 01, 2025

Problem Comments

Solution Comments

Show comments
Why should you share code?
In a discussion on LInkedin about my recent blog post, Do these...
3
6

Problem Recent Solvers50

Suggested Problems

More from this Author45

Problem Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!