Help me in solving SUSSTR problem

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

@pre_b_850
here plzz refer my c++ code for better understanding of the logic

#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--)
	{
	    int n;
	    cin>>n;
	    string s;
	    cin>>s;
	    string ans;
	    for(int i=0,j=n-1,k=0;k<n;k++)
	    {
	        if(k%2==0)
	        {
	            if(s[i]=='0')
	            {
	                ans='0'+ans;
	            }
	            else
	            ans.push_back('1');
	            i++;
	        }
	        else
	        {
	            if(s[j]=='1')
	            {
	                ans='1'+ans;
	            }
	            else
	            ans.push_back('0');
	            j--;
	        }
	    }
	    cout<<ans<<endl;
	}

}