Ans is correct but the order getting wrong

@deepgarg46 Bench mark your code with this code :

import java.util.*;

public class Main {
    public static void lexicoLarger(String str, String osf, boolean flag, String originalString) {
        if (str.length() == 0) {
            if (osf.compareTo(originalString) > 0)
                System.out.println(osf);
            return;
        }
        for (int i = 0; i < str.length(); i++) {
            String ros = str.substring(0, i) + str.substring(i + 1);
            char ch = str.charAt(i);
            if (flag) {
                lexicoLarger(ros, osf + ch, flag, originalString);
            } else {
                if (str.charAt(i) >= str.charAt(0)) {
                    lexicoLarger(ros, osf + ch, flag || ch > str.charAt(0), originalString);
                } else if (str.charAt(i) < str.charAt(0)) {
                    // No call
                }
            }
        }
    }

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        String orig = new String(str);

        char[] temp = str.toCharArray();
        Arrays.sort(temp);
        str = new String(temp);

        lexicoLarger(str, "", false, orig);
    }

}

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.