


There can be more than one possible string with maximum size. In that case, you can return any of them.
The first line contains an integer 'T' which denotes the number of test cases or queries to be run.
The first line of each test case contains three space separated integers, ‘X’, ‘Y’, and ‘Z’, which denote the maximum number of ‘a’, ‘b’, and ‘c’ respectively answer strings can have.
For each test case, the output will be “1” if you have returned the correct answer, else it will be “0”.
You do not need to input or print anything, and it has already been taken care of. Just implement the given function.
1 <= T <= 5
0 <= X, Y, Z <= 10^3
X + Y + Z >= 1
Time Limit: 1 sec
Given 'X', 'Y' 'Z' you can try all combinations of possible strings and return the string that has a maximum length. You can create all possible strings by inserting all the three letters i.e. ‘a’, ‘b’, ‘c’ at each ‘i -th’ position in string by taking care of the condition that no three characters should be the same. For example at ‘i -th’ position in the string you can add the letter ‘a’, if and only if 'X' greater than 0 and the last two letters in string i.e. at position ‘i - 1’ and ‘i - 2’ are not ‘a’. Similarly of ‘b’ and ‘c’. At last check all the possible strings you generated and return the string with the maximum size.
The function will take two parameters:
The function will take four parameters:
Let’s start with an empty string and gradually add available characters in it, as we wanted to maximize the length of string, so we greedily add that character whose current availability is maximum i.e current limit is highest. We cannot add three consecutive same characters, thus we add that character two times only and then find the next different characters with maximum availability and that character.
For example, if we have 5 ‘a’, 3 ‘b’, 1 ‘c’.
We repeat this process until either all available characters are used or we end up with only one type of character. We can use max heap data structure to get max available character after each update.
Suppose there are only two characters available and say only ‘a’ and ‘b’ with count 'X' and 'Y'. Also, suppose that 'X' is very high than 'Y'. Then to maximize the size of the string. We construct a string like this - “aabaabaab...”. We can extend this greedy approach to three characters. The idea is to keep track of currently available characters and add the most available character till we can add i.e. we can add at most two times consecutively and then add any of the other two characters. We can do this iteratively by keeping track of count current available characters and the last two characters in the string. In case there is only one type of character is left i.e count of the other two characters becomes 0, and the last two letters in the string are the same as the character that is left, then we cannot increase the size of the string further.