There are 5 houses in school and they are represented as R,G,B,Y,L. A school teacher ask his students to stand in a row. Now, if 2 or more students of same house stand next to each other, the school teacher keeps only 1 of them in row and removes the rest. Find number if students removed.
N-number of test cases
Number of students removed for each case in different lines
Case 3, students marked in RED are removed, 3 of them- RGGRGRGRGRGYYLYBBRGBYL
if($arr[$j] eq $arr[$j+1])
Simple enough, just compare two consecutive items and increase count if matches