Question: Create a C program that will accept an input sequence of integer value containing digit 1 and 2 only and store in into Array A

Create a C program that will accept an input sequence of integer value containing digit 1 and 2 only and store in into Array A. Your task is to store it into a new array, Array B such that there are no matching adjacent element. To do this, you are allowed to delete zero or more digits in Array A. Your task is to find the minimum number of required deletions.

For example, given the input A=112112 , remove an 1 at positions 0 and 3 to make A=1212 in 2 deletions.

Input Format

The first line contains an integer x, the number of queries.

Constraints

  • 1 <= q <=10
  • 1<=x<=(10^5)
  • Input should only contain 1 and 2

Output Format

For each query, print the minimum number of deletions required on a new line. Use Do=while to repeat the execution of the program

Sample Output

  • 1111 - 3 deletion

Sample output

  • 22222 - 4 deletion

Sample output

  • 12121212 - 0 deletion

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!