ALTARAY - Editorial

#include<bits/stdc++.h>
#define ll long long int
#define mod 1000000007
#define inf 1e9+8
using namespace std;
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
ll t;
cin>>t;
while(t–){
ll n;
cin>>n;
vectora(n);
vectorb(n,0);
for(ll i=0;i<n;i++)
cin>>a[i];
for(ll i=0;i<n;i++)
if(a[i]>0)
a[i]=1;
else
a[i]=-1;
b[n-1]=1;
for(ll i=n-2;i>=0;i–){
if(a[i]>0 && a[i+1]<0 || a[i]<0 && a[i+1]>0)
b[i]=b[i+1]+1;
else
b[i]=1;
}
for(ll i=0;i<n;i++)
cout<<b[i]<<’ ';
cout<<endl;
}
return 0;
}

package cp.codechef;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class ALTARAY {
private static BufferedReader bread=new BufferedReader(new InputStreamReader(System.in));

private static int[] readInput(int n) throws IOException {
	int i=0;
	int[] arr=new int[n];
	StringTokenizer st=new StringTokenizer(bread.readLine());
	while(st.hasMoreTokens()) {
		arr[i++]=Integer.parseInt(st.nextToken());
	}
	return arr;
}

public static void main(String[] args) throws IOException{
	int t=Integer.parseInt(bread.readLine());
	while(t-->0) {
		int n=Integer.parseInt(bread.readLine());
		int[] arr=readInput(n);
		StringBuilder sb=new StringBuilder();
		sb.append("1 ");
		int last=1;
		for(int i=n-2;i>=0;i--) {
			if(arr[i+1]>0 &&arr[i]<0   || arr[i+1]<0 &&arr[i]>0) {
				last+=1;
				sb.append(String.valueOf(last)+" ");
			}
			else {
				last=1;
				sb.append("1 ");
			}
		}
		System.out.println(sb.reverse().toString().trim());
	}
	
}

}
What’s wrong with my code? Am getting WA