## Lonely Integer

Given an array of integers, where all elements but one occur twice, find the unique element. Example a = [1,2,3,4,3,2,1] The unique element is 4. Function Description Complete the lonelyinteger function in the editor below. lonelyinteger has the following parameter(s): int a[n]: an array of integers Returns int: the element that occurs only once Input Format The first line contains a single integer, n, the number of integers in the array. The second line contains n spac

## Maximizing XOR

Given two integers, l and r, find the maximal value of a xor b, written a+b, where a and b satisfy the following condition: l <= a <= b <= r For example, if l=11 and r=12, then 11 + 11 = 0 11 + 12 = 7 12 + 12 = 0 Our maximum value is 7. Function Description Complete the maximizingXor function in the editor below. It must return an integer representing the maximum value calculated. maximizingXor has the following parameter(s): l: an integer, the lower bound, inclusive r: an

## Counter game

Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of 2. If it is, they divide it by 2. If not, they reduce it by the next lower number which is a power of 2. Whoever reduces the number to 1 wins the game. Louise always starts. Given an initial value, determine who wins the game. Example n = 132 It's Louise's turn first. She determines that 132 is not a power of 2. The next lower power of 2 is 128, so she subtracts that from 132 and pas

## Xor-sequence

An array, A, is defined as follows: A0 = 0 Ax = Ax-1 + x for x >0, where is the symbol for XOR You will be given a left and right index l r. You must determine the XOR sum of the segment of A as A[l] + A[l+1] + ... + A[[r-l] + A[r]. For example, A = [0,1,3,0,4,1,7,0,8]. The segment from l=1 to r=4 sums to 1 +3 +0 + 4 = 6. Print the answer to each question. Function Description Complete the xorSequence function in the editor below. It should return the integer value calculated.

## Sum vs XOR

Given an integer , find each such that: 0 <= x <= n n + x = n+x where + denotes the bitwise XOR operator. Return the number of x's satisfying the criteria. Example n = 4 There are four values that meet the criteria: 4 + 0 = 4 + 0 = 4 4 + 1 = 4 + 1 = 5 4 + 2 = 4 + 2 = 6 4 + 3 = 4 + 3 = 7 Return 4. Function Description Complete the sumXor function in the editor below. sumXor has the following parameter(s): - int n: an integer Returns - int: the number of values found