
1. At index 0 the happiness value of his friend is 3 and the happiness value of Ninja is 2. Both are unequal so ‘K’ remains the same.
2. At index 1 the happiness value of his friend is 2 and the happiness value of Ninja is 2. Both are equal so ‘K’ becomes 4.
3. At index 2 the happiness value of his friend is 1 and the happiness value of Ninja is 4. Both are unequal so ‘K’ remains the same.
4. At index 3 the happiness value of his friend is 4 and the happiness value of Ninja is 4. Both are equal so ‘K’ becomes 8.
The first line contains an integer 'T' which denotes the number of test cases or queries to be run. Then the test cases follow.
The first line of each test case contains two integers ‘N' and ‘K’ denoting the number of friends and the initial happiness value ofNinja respectively.
The second line of each test case contains 'N' single space-separated integers, denoting the happiness value of each friend.
For each test case, print an integer denoting the final happiness value of Ninja after all the handshakes.
The output of each test case will be printed in a separate line.
You are not required to print the expected output, and it has already been taken care of. Just implement the function.
1 <= T <= 100
1 <= N <= 10 ^ 4
1 <= K <= 10 ^ 3
1 <= FRIENDS[i] <= 10 ^ 6
Where 'FRIENDS[i]' denotes the happiness value of the friend at the ‘i’th index, respectively.
Time Limit: 1 sec
The idea behind this approach is to simply iterate the list/array ‘FRIENDS’ and compare the happiness value of Ninja with that of his friend. If both are the same then double the happiness value of Ninja and repeat the same for the rest of the friends.
Here is the complete algorithm: