Jumping Tokens
Practice
2.6 (9 votes)
Medium
Ad hoc
Approved
Problem
39% Success 1193 Attempts 30 Points 5s Time Limit 256MB Memory 1024 KB Max Code

You are given a row of n tokens in a row colored red and blue.

In one move, you can choose to perform a capture. A capture chooses a token, and makes a jump over exactly one other token, and removes a token of the opposite color.

More specifically, given three adjacent tokens we can convert it into the following state with two adjacent tokens:

  • \(RxB \to xR\)
  • \(BxR \to xB\)
  • \(RxB \to Bx\)
  • \(BxR \to Rx\)
where x is a token of an arbitrary color.

Given the initial row of tokens, return the minimum possible length of the resulting row after a series of captures.

Input Format:

The first line will contain the number of test cases T.
Each test case can be described with one line.
This line will contain a string consisting of only characters 'R' and 'B' denoting the colors in the row.

Output Format:

Output T numbers, the answers to each problem.

Constraints

There is no partial credit for this problem.

There is only one file for this problem. The file has the following constraints.
\(T = 1000\)
\(1 ≤ n ≤ 50\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
8 votes
Tags:
Basic ProgrammingBasics of ImplementationData StructuresHash MapsHash TablesImplementationMedium
Points:30
28 votes
Tags:
AdhocBasic ProgrammingBasics of ImplementationImplementationMedium
Points:30
22 votes
Tags:
Basic ProgrammingC++