#529 Minimum Number Without Leading Zeroes

Companies:
T-Bank
Themes:
AlgorithmsStringsPractice

A string s containing only digits from 0 through 9 is given, and not all of its elements are equal to 0. Rearrange its digits so that the number represented by the string is as small as possible and the string contains no leading zeroes.

A number contains leading zeroes when the number is not zero but starts with the digit 0. For example, 01 and 0303 contain leading zeroes, while 0 and 30000 do not.

Input:

  • A string s, where 1 <= |s| <= 9;
  • The string is guaranteed to contain at least one non-zero digit.

Output:

  • A string representing the minimum possible number without leading zeroes.

Examples:

"682902" -> "202689"
"01"     -> "10"
public static String solve(String s) {
    // TODO
}

Question review

Mentor
Answer as you would in a real interview. I’ll ask follow-up questions, then compare your answer with the reference answer and show your accuracy as a %.
Sign in to start the dialogue The mentor keeps the context of the current question and your previous messages.
Sign in