Help me in solving SUSSTR problem

My issue

Can Anyone guide me on , how we can solve this problem using deque ? I am trying to solve it using deque

Problem Link: https://www.codechef.com/problems/SUSSTR

@srajvardhan080
refer my c++ code

#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 fans;
	    deque<char> ans;
	    for(int i=0,j=n-1,k=0;k<n;k++)
	    {
	        if(k%2==0)
	        {
	            if(s[i]=='0')
	            {
	                ans.push_front('0');
	            }
	            else
	            ans.push_back('1');
	            i++;
	        }
	        else
	        {
	            if(s[j]=='1')
	            {
	                ans.push_front('1');
	            }
	            else
	            ans.push_back('0');
	            j--;
	        }
	    }
	   for(auto x:ans)
	   fans.push_back(x);
	   cout<<fans<<endl;
	}

}