PROBLEM LINK:
PLAY THE GAME
Problem Code: PLGA
Difficulty: Cakewalk
The problem follows a simple logic where Ganesh is the next Kohli only when 0 and 1 occur alternatively in the given input. Ganesh is out when 0 and 1 don’t occur alternatively and Ganesh is a pure single if the input size is 1 character.
The important point that needs to be noted here is that the constraint for the number of characters is 200. If one uses a character array then the size of the character array needs to be at least 201 since we need an extra space for storing “/0”. The best approach would be to use a string datatype in C++ wherein one need not have to necessarily specify the size of the string.
The problem can be solved easily by using a flag variable to determine the state of the output.
The below code is the most basic and simplest implementation of the given problem.
Time complexity = O(n)
Setter’s Solution : Solution