My issue
i cant get the solution
My code
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int t = scanner.nextInt(); // Number of test cases
scanner.nextLine(); // Consume the newline
for (int i = 0; i < t; i++) {
int n = scanner.nextInt(); // Length of the string S
String s = scanner.next(); // Binary string S
String result = findResultantString(s);
System.out.println(result);
}
}
private static String findResultantString(String s) {
StringBuilder t = new StringBuilder();
int left = 0, right = s.length() - 1;
while (left <= right) {
if (s.charAt(left) <= s.charAt(right)) {
t.append(s.charAt(left));
left++;
} else {
t.append(s.charAt(right));
right--;
}
}
return t.toString();
}
}
Learning course: Stacks and Queues
Problem Link: Suspense String Practice Problem in Stacks and Queues - CodeChef