Compiler and Parsers

Why my code says WA i cannot get.
Please Help


class Compiler


    static String a[];
    static int pos;
    public static void main(String args[])throws Exception
        BufferedReader br=new BufferedReader(new InputStreamReader(;
        int t=Integer.parseInt(br.readLine());
        for(int z=0;z<t;z++) {
            a=new String[1000000];
            long l=0;
            String s=br.readLine();
            for(int i=0;i<s.length();i++) {
                else {
                    if(pos>0) {
                        String k=pop()+">";
    static void push(String s) {
    static String pop() {
        String k=a[pos-1];
        return k;

When ever you get


shouldn’t you end the loop? so i think you have to keep


that might help… i think so. (i don’t know java, so i am not sure of the boolean condition)

bro there is nothing called “pos<0” and this is working in all the test cases i have made and of the question.

then try these cases::



i checked your code in, which gave wrong responses for these cases

@eightnoteight for your first testcase the ans should be 2 or anything else??
and for the second it must be 8?
what is the problem?

the first case should give 4, but your code gives 2

the second case should give 0, but your code gives 8

Please help. I have confusion, I thought that we need to find the longest valid sequence in the expression as the test case:
<>>> gives 2 even though full expr is invalid.

<><> should give 4
<>< should give 2
<<<><>> should give 6

my submission:

Is this right?