String Game ( DSA INTERVIEW PREPARATION PROBLEMS AND SOLUTIONS )

 Alice and Bob are playing a game on a binary string 

S of length N.

Alice and Bob alternate turns, with Alice going first. On their turn, the current player must choose any index 1i<|S| such that SiSi+1 and erase either Si or Si+1 from the string. This reduces the length of S by one, and the remaining parts of S are concatenated in the same order.

The player who is unable to make a move loses.

Determine the winner if both players play optimally.

Input Format

  • The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows.
  • The first line of each test case contains a single integer N, the length of the string.
  • The second line contains the binary string S of length N.

Output Format

For each test case output Alice if Alice wins the game, otherwise output Bob. The output is not case-sensitive, so for example "Bob", "boB" and "Bob" are all considered equivalent.

Constraints

  • 1T1000
  • 2N105
  • S is a binary string
  • Sum of N over all test cases does not exceed 2105.

Sample Input 1 

3
4
1111
3
110
4
1010

Sample Output 1 

Bob
Alice
Bob

Explanation

Test Case 1: There is no such index i such that SiSi+1. So, Alice does not have any move and loses, making Bob the winner.

Test Case 2: Alice can choose i=2 (because S2=1 and S3=0) and remove S3. After this move, the remaining string is "11". Bob now has no moves and thus loses.

Previous
Next Post »