Q.1 There are N tiles (numbered from 0 to N−1). Each tile is made of two squares that are colored either red (represented by the letter "R") or green (represented by "G"). A tile is described by a two-character string representing the respective colors of the left and right squares. The tiles cannot be rotated (which means that "RG" and "GR" tiles are different). Two tiles can be placed next to each other if the color of their adjacent squares is the same.
What is the length of the longest possible sequence that can be created using the provided tiles?
Write a function:
int solution(char *A[], int N);
that, given an array A of N strings, representing the tiles, returns the maximum number of tiles that can be arranged in a sequence.
Examples:

we can select tiles 0, 2, 3, 4, 5 (underlined in the picture above) and arrange them into the sequence GR - RR - RG - GR - RR:

The function should return 5.

we can select tiles 0, 1, 3 (underlined in the picture above) and arrange them into the sequence GG - GG - GG:

The function should return 3.

all tiles can be used without reordering them. The function should return 4.
Write an efficient algorithm for the following assumptions:
N is an integer within the range [1..100,000];
each string in array A is one of the following: "RR", "RG", "GR", "GG".
Q.2 A game board has a row of N+1 fields, numbered from 0 to N from left to right. One letter ("a" or "b") is written between every two adjacent fields. Letters on the board are described by a string L of length N, where L[K] (for K within the range [0..N−1]) is the letter between fields K and K+1.
For example, given L = "aaabab" and N = 6 the game board at the beginning will look like this:

There is a game piece standing on some field on the board. It can move one field to the left or to the right, passing over one of the letters. The letter over which the game piece passes switches to the opposite one ("a" becomes "b" and "b" becomes "a"). The game piece can move multiple times, so letters may also be switched multiple times.
For above example, if the game piece stood on the field number 3 and then moved to the left, the game board would look like the picture below:

The game piece initially stands on a field designated as the start. What is the minimum number of moves after which there will be the same number of letters "a" and "b" on the board? If it is impossible to achieve such a situation, return −1.
Write a function:
function solution(L, start);
that, given a string L of length N and an integer start, returns the minimum number of moves such that, after those moves, there will be the same number of letters "a" and "b" on the board (or returns −1 if it is impossible).
Examples:
For L = "aaabab", start = 0, the game piece must move one field to the right. This way, the first letter of L will be switched to produce string "baabab". Both letters occur in this string three times. The function should return 1.
For L = "aaabab", start = 6, the game piece has to move five times to the left:
"aaabab" → "aaabaa" → "aaabba" → "aaaaba" → "aababa" → "abbaba"
The function should return 5.
For L = "ababa", start = 1, it is impossible to equalize the number of letters "a" and "b". The function should return −1.
For L = "babbaa", start = 2, the number of letters "a" and "b" is already equal. The function should return 0.
Assume that:
N is an integer within the range [1..100];
string L is made only of the characters 'a' and/or 'b';
start is an integer within the range [0..N].
In your solution, focus on correctness. The performance of your solution will not be the focus of the assessment.