My issue
what is wrong in this code
My code
import java.util.*;
import java.lang.*;
import java.io.*;
class Codechef
{
public static String smallestSpell(String spell) {
int minIdx = 0;
int x=1;
for (int i = 1; i < spell.length(); i++) {
if (spell.charAt(i) < spell.charAt(i-1)) {
minIdx =i-1;
break;
}
x++;
if(x==spell.length()-1){
return spell.substring(0, x) ;
}
}
return spell.substring(0, minIdx) + spell.substring(minIdx + 1);
}
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner scanner = new Scanner(System.in);
int T = scanner.nextInt();
for (int t = 0; t < T; t++) {
int N = scanner.nextInt();
String spell= scanner.next();
System.out.println(smallestSpell(spell));
}
}
}
Problem Link: Spell Shortening Practice Coding Problem - CodeChef