Enter the Matrix
All submissions for this problem are available.
Its the 22nd century and the terror of Codezilla is at its height. Codezilla is the most evil and dangerous hacker that ever existed. He has broken all systems of governance and the world has descended into anarchy. Eon, a young hacker, is fed up with the situation and has decided to put an end to Codezilla.
Eon meets a mysterious man called Cypher who is on the same mission. He tells Eon that to fight against Codezilla first he needs to get out of the real world and enter the Matrix. For this he needs to take some pills.
Cypher gives a set of pills to Eon. There are three types of pills: Blue,Red and Green. Eon can select any number of consecutive pills but he must take atleast one red pill, one blue pill and one green pill to enter the matrix. As eating more pills can be harmful, help Eon select the minimum number of pills.
The first line of the input contains an integer T denoting the number of test cases. Each of the next T lines contains a string depicting the set of pills. Each character of the string is 'B', 'R' or 'G' standing for blue, red and green pills respectively.
For every test case, print in a single line the minimum number of consecutive pills that Eon should take so that he gets atleast one pill of each colour.
- 1 ≤ T ≤ 10
- 3 ≤ Length of string ≤ 100000
- The input string will contain atleast one each of 'B', 'R' and 'G'.
Input: 2 BBRG RGGGBBR Output: 3 4
Example case 1. Eon selects the pills from 2 to 4, so he takes 3 pills.
Example case 2. Eon can select 5 pills from 1 to 5 or he can select 4 pills from 4 to 7. So the answer is 4.
|Tags||cdzl14, implementation, simple, tussharsingh13|
|Time Limit:||0.356667 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, GO|
Fetching successful submissions