Archive / 2021 / November 2021
Housing Scheme
An engineer together with his architect is designing a scheme. The scheme has houses but it also has office buildings. All the buildings here are to be built next to each other such that they are approximately in a straight line.
The difference between the number of floors of any two adjacent buildings has to be greater than or equal to 2 and less than or equal to 4. The scheme always has two or more buildings. For any given number of buildings b in the scheme, find an arrangement of buildings that satisfies the above condition.
Each building is numbered from 1 to b based on the number of floors it has (If the building has only one floor the building is numbered as 1) and the number of floors in each building should be unique (That is for b number of buildings there can only be one bulding with one floor).
Input Format
- The first line contains an integer t, the number of test cases. Then t test cases follow.
- Each test case is describes the number of buildings that can be there in the scheme.
Output Format
- Print t lines.
- Each line outputs the arrangement of buildings meeting the given requirements. If there are multiple arrangements, then print any of them. If the buildings can’t be arranged to satisfy the given conditions print -1.
Constraints
- 1 \(\leq\) t \(\leq\) 100
- 2 \(\leq\) b \(\leq\) 1000
Sample Input 0
8
3
10
4
22
11
9
15
8
Sample Output 0
-1
9 7 5 3 1 4 2 6 8 10
3 1 4 2
21 19 17 15 13 11 9 7 5 3 1 4 2 6 8 10 12 14 16 18 20 22
11 9 7 5 3 1 4 2 6 8 10
9 7 5 3 1 4 2 6 8
15 13 11 9 7 5 3 1 4 2 6 8 10 12 14
7 5 3 1 4 2 6 8
Open on HackerRank ↗ · Markdown source · Back to the archive