Round 1
Questions:
Q1
For two positive integers, lo and hi, and a limit k, find two integers, a and b, satisfying the following criteria. Return the value of a • b. The • symbol denotes the bitwise XOR operator.
- lo <= a < b <= hi
- The value of a • b is maximal for a • b ≤ k.
Example:
lo = 3
hi = 5
k = 6:
The maximal usable XORed value is 6 because it is the maximal value that is less than or equal to the limit k = 6.
Function Description
Complete the function maxXor in the editor below. The function must return an integer denoting the maximum possible value of a • b for all a • b ≤ k.
maxXor has the following parameters:
int lo: an integer
int hi: an integer
k: an integer
Constraints
- 1 ≤ lo < hi ≤ 10^5
- 1 ≤ k ≤ 10^4
Q2
An array of integers is defined as being in meandering order when the first two elements are the respective largest and smallest elements in the array and the subsequent elements alternate between its next largest and next smallest elements. In other words, the elements are in order of [first_largest, first_smallest, second_largest, second_smallest, ...].
Example
The array [-1, 1, 2, 3, -5] sorted normally is [-5, -1, 1, 2, 3]. Sorted in meandering order, it becomes [3, -5, 2, -1, 1].
Function Description
Complete the function meanderingArray in the editor below.
meanderingArray has the following parameters:
unsorted[n]: the unsorted array
Returns:
int[n]: the array sorted in meandering order
Constraints
- 2 ≤ n ≤ 10^5
- -10^6 ≤ unsorted[i] ≤ 10^6
- The unsorted array may contain duplicate elements.
Candidate's Approach
No approach provided.
Interviewer's Feedback
No feedback provided.