I have been trying to solve COMPILER PROBLEM,
I am confused as in why i am getting wrong answer.
It would be great if somebody is able to point out the error.
Here is the code,
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Stack;
class StackImp {
static Stack<String> sta;
public static void main(String[] args) throws NumberFormatException, IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
while(t-->0){
String input = br.readLine();
String syms[] = input.split("");
int count = 0;
sta = new Stack<String>();
for(int i=0;i<syms.length;i++){
if(syms[i].equals("<")){
sta.push("<");
count+=1;
}
else if(syms[i].equals(">")&&!sta.isEmpty()){
count+=1;
sta.pop();
}
}
if(sta.isEmpty())
System.out.println(count);
else
System.out.println(0);
}
}
}