Ad
  • Default User Avatar

    Not necessary. There's a simple trick that makes it lightning fast.

    That being said, the lower bound is effectively 0.

  • Custom User Avatar

    plz provide upper and lower bound

  • Custom User Avatar

    how you solve this.i got time limit

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    Unit test for 1021 have mistake. Should return 1201

  • Custom User Avatar

    getting "DescendingOrder.java:30: error: reached end of file while parsing" but it seems my code work fine.
    whats wrong here?
    import java.util.ArrayList;
    import java.util.Collections;
    public class DescendingOrder {
    public static int sortDesc(final int num) {
    ArrayList list = new ArrayList();
    StringBuilder stringBuilder = new StringBuilder();
    int num1 = num;
    if (num1 < 10) {
    return num1;
    } else {
    while (num1 != 0) {
    int n = num1 % 10;
    num1 = num1 / 10;
    list.add(n);

            }
            Collections.sort(list);
            Collections.reverse(list);
            int len = list.size();
            //System.out.println(len);
            for (Integer i : list
                    ) {
                stringBuilder.append(String.valueOf(i));
    
            }
            String s = stringBuilder.toString();
            int n = Integer.parseInt(s);
            return n;
    

    }
    }