Help me in solving BLOBBYVOLLEY problem

My issue

Can anyone help me understand the logic behind this test case?
Test Case causing error - “BBBB”
Expected output - “0 3”
My Output - “0 4”

My code

/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		for(int j=0; j<t; j++){
		    int n = sc.nextInt();
		    String s = sc.next();
		    int A = 0;
		    int B = 0;
		    char server = s.charAt(0);
		    for(int i=0; i<n; i++){
		        if(s.charAt(i) == server){
		            if(s.charAt(i) == 'A'){
		                A = A + 1;
		            }
		            if(s.charAt(i) == 'B'){
		                B = B + 1;
		            }
		        }
		        if(s.charAt(i) != server){
		            server = s.charAt(i);
		        }
		    }
		    System.out.println(A + " " + B);
		}
	}
}

Learning course: Strings using Java
Problem Link: CodeChef: Practical coding for everyone

char server = s.charAt(0);

this line causes the Error. The first server is supposed to be fixed: Initially, Alice is the server, and Bob is the receiver.

1 Like

Hey! Thank you so much! I somehow missed this line in the problem statement :sweat_smile: