Wrong Bubble Sort
InterviewTime limit1sMemory limit1024 MB
Given N, output a length-N array of values from 0 to 10000 that Jeongyeon's bubble sort fails to sort correctly.
- Level
Medium5 of 10
- Topics
- Sorting, Simulation
- Solved
- No attempts yet
Problem
Jeongyeon learned bubble sort in a school programming class and wanted to put it to use, so she took on a sorting problem on an online judge. The problem was as follows.
"Given a sequence of numbers , , , , write a program that sorts them in ascending order."
Jeongyeon thought her code was perfect and submitted it, but unfortunately got "Wrong answer." Her bubble sort code is shown below.
for (int i = N - 1; i > 0; i--) {
for (int j = i - 1; j >= 0; j--) {
if (A[j] > A[j + 1]) {
int tmp = A[j];
A[j] = A[j + 1];
A[j + 1] = tmp;
}
}
}
Given , construct a counterexample input for Jeongyeon's code. Specifically, build a sequence of length that her code does not sort correctly. Every element of must be an integer from to , inclusive, and her code must fail to sort the numbers you output.
Such a sequence exists for every that satisfies the input constraints. If several sequences work, print any of them.
Input
The first line contains an integer .
Output
On the first line, print integers , , , separated by spaces that satisfy the conditions above.
Limits
- ()