Omar's Bug
InterviewTime limit1sMemory limit128 MB
For each query with N, X and a flag, build the lexicographically smallest sorted array that makes the buggy lower bound return a right or wrong answer.
- Level
Medium5 of 10
- Topics
- Binary search, Greedy
- Solved
- No attempts yet
Problem
Omar is the youngest programmer in the world. He is only 11 months old. He read an explanation of binary search and decided to write it himself.
Here is the function he wrote. The syntax is valid and it behaves the same way in C++ and in Java.
int findFirstGreaterThanOrEqual(int array[], int N, int X) {
int start = 0, end = N;
while (start < end) {
int middle = (start + end) / 2;
if (array[middle] > X) {
end = middle;
} else {
start = middle + 1;
}
}
return start;
}
The function is always called with arguments that satisfy all of these conditions.
- The first argument is an array holding at least 1 and at most 99 integers.
- The integers in the array are distinct and sorted in increasing order.
- Every integer in the array is positive and at most 100.
- is the number of elements in the array.
- is a positive integer that is at most 100.
This is how Omar wants the function to behave. If the array holds no integer greater than or equal to , the function returns . Otherwise it returns the index of the smallest integer in the array that is greater than or equal to . The first element has index 0.
The function has a bug, so it returns a wrong value for some inputs, and Omar is too young to find it. Help him by building arrays that test his function.
Input
The first line holds one integer , the number of test cases ().
Each of the next lines describes one test case with three integers separated by a single space, (, , ). is the value of the second argument and is the value of the third argument. If is 1, build an array that makes the function return the correct value for those arguments. If is 2, build an array that makes the function return a wrong value. In both cases the array must satisfy the conditions above.
Correct and wrong are judged against the behaviour Omar wants, not against what the code actually does.
Output
For each test case print one line with the integers of your array, in the order they appear in the array, separated by a single space. If more than one array satisfies the conditions, print the lexicographically smallest one.
When two arrays of the same length are compared, the lexicographically smaller one is the array holding the smaller value at the first index where they differ.