import java.util.*;

class TestClass {
    public static void main(String args[]) throws Exception {
        //Scanner
        Scanner s = new Scanner(System.in);

        int t = s.nextInt();

        while (t != 0) {
            int flag[] = new int[150];
            String sa = s.nextLine();
            char c;
            int count1 = 0, count2 = 0, count3 = 0;

            for (int i = 0; i < sa.length(); i++) {
                c = sa.charAt(i);
                flag[c]++;
            }

            count1 = (flag['('] > flag[')']) ? flag[')'] : flag['('];
            count2 = (flag['{'] > flag['}']) ? flag['}'] : flag['{'];
            count3 = (flag['['] > flag[']']) ? flag[']'] : flag['['];
            System.out.println((count1 + count2 + count3) * 2);
            t--;
        }
    }
}
Your Code's Output
0
8
6
2
4
Expected Correct Output
8
6
2
4
2

I am getting correct output but there's a zero in the beginning of all outputs?

0 Answers