Chef and Feedback
Practice this coding question on Coding Gurukul.
Problem statement
A kitchen display receives a compact feedback stream made only of zeroes and ones. The monitoring team calls a stream Good when it contains a short alternating signal: either 010 or 101. All other streams are classified as Bad. Your program will apply this exact rule to each incoming stream before the display files it. Your task For each binary string S, determine whether at least one contiguous substring equals 010 or 101. Print Good if such a substring exists and Bad otherwise. Important details The three characters must be consecutive; choosing separated positions is not allowed. A matching substring may occur at either end, and multiple matches still produce just one Good result. A string shorter than three characters is always Bad. Worked example The stream 11010 contains 101 at positions 2 through 4, so it is Good. The stream 001100 has no alternating three-character window, so it is Bad.
Input format
The first line contains T. Each of the next T lines contains one nonempty binary string S.
Output format
Print Good or Bad, with this capitalization, for each stream on its own line.
Constraints
1 <= T <= 100; 1 <= length of S <= 100000; S contains only 0 and 1.
Sample input
2 11010 001100
Sample output
Good Bad
Sign in to run or submit a solution in C++, Java or Python.