Adobe Interview Question
Software Engineer / Developers@PKT, good logic.
Typing mistake , Small correction, in your solution 7 and 8 in same column.
5 and 6 also in same column.
correct one
9 5 13 1 14 2 10 6
11 7 15 3 16 4 12 8
make pairs {1,3} {2,4} {5,6}.. start off by writing the groups vertically in alternate columns (starting with column 2)
wrap back when you reach the last column
i.e.
- 1 - 2 -
- 3 - 4 -
5 1 6 2
7 3 8 4
similarly for 16 elements
- 1 - 2 - 5 - 6
- 3 - 4 - 7 - 8
9 1 10 2 13 5 14 6
10 2 11 4 15 7 16 8
make pairs {1,3} {2,4} {5,7}.. start off by writing the groups vertically in alternate columns (starting with column 2)
wrap back when you reach the last column
i.e.
- 1 - 2 -
- 3 - 4 -
5 1 6 2
7 3 8 4
similarly for 16 elements
- 1 - 2 - 5 - 6
- 3 - 4 - 7 - 8
9 1 10 2 13 5 14 6
10 2 11 4 15 7 16 8
Group the numbers in pairs of odd and even numbers {1,3} {2,4} {5,7} {6,8}
If you start with odd numbers then pick the largest odd pair {5,7} in the first column, followed by the smallest odd pair {1,3}, followed by the largest even pair {6,8}, followed by the smallest even pair {2,4}. For example:
5-1-6-2
7-3-8-4
The order of the numbers within the pair does not matter as long as you go large odd, small odd, large even, small even. For example:
7-1-8-2 and 7-3-8-4
5-3-6-4 5-1-6-2
If you start with even numbers, then start with the smallest pair of even numbers in the first column, then the larger pair, then the smalles pair of odd numbers, then the largest pair of odd numbers. For example:
2-8-1-5
4-6-3-7
Again you move around the numbers in a column without affecting the results:
4-8-3-5 and 2-6-1-7
2-6-1-7 4-8-3-5
1. keep no. in group of two alternate numbers.
{1,3} {2,4} {5,7} {6,8}
2.now fill the center 4 block with two group containing first and last number.
(1,3) {6,8}
3. now fill with other group.
5 1 8 4
7 3 6 2
______________________________________________
for 16 numbers
{1,2,3,4,5,6........15,16}
- PKT March 19, 2011