Rajeev and Beautiful Row
All submissions for this problem are available.
There are N students in a row, some Student are facing right and some left. Rajeev thinks the row will look good if all the students will face in the same direction.
In one step you can move any one segment of consecutive Students. After moving a segment, all students facing right will face toward left and vice versa In how many minimum number of steps students will face in the same direction?
- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
- Each test case is described in one line containing a string S of N characters, the i-th character is R if the i-th student is facing right and L if it is facing towards left.
For each test case, output a single line containing the minimum number of move needed to make all students point to the same direction.
- 1 ≤ T ≤ 3000
- 1 ≤ N ≤ 50
Input: 2 RRLLLRRR RRRLLRL
Output: 1 2
Example case 1.In 1 step we can move all the students facing towards left in right.
Example case 2.In 2 steps we can move either left segments towards right or both right segment towards left.
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, kotlin, PERL6, TEXT, SCM chicken, CLOJ, COB, FS|
Fetching successful submissions