GATE Computer ScienceHardGATE CS (PYQ pattern)
A 4 x 6 matrix (4 rows, 6 columns) holds 1 to 24 in row-major order. Its elements are visited in an anticlockwise spiral that starts at the top-left corner and first goes down the first column. What is the sum of the 10th, 15th and 20th visited elements?
- A. 47
- B. 37
- C. 43
- D. 31
Correct answer: B. 37
The anticlockwise spiral is 1 7 13 19 20 21 22 23 24 18 12 6 5 4 3 2 8 14 15 16 17 11 10 9. The 10th, 15th and 20th elements are 18, 3 and 16, summing to 37. The usual clockwise spiral gives 47.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- int a[] = {1,1,2,2,2,3,4,4,5,5,5,5,6}; int w = 2; for (int i = 2; i < 13; i++) if (a[i] != a[w - 2]) a[w++] = a[i]; What is w after the…
- int p[10] = {1}; for (int r = 1; r <= 8; r++) for (int j = r; j >= 1; j--) p[j] += p[j - 1]; How many of p[0..8] are odd, and what is p[3]…
- Lomuto partition with the last element as pivot is applied to [34, 8, 64, 51, 32, 21, 78, 5, 40, 27]: i = -1; for j = 0 .. n-2, if a[j] <=…
- int cand = -1, cnt = 0, ch = 0; int a[] = {3,3,4,2,4,4,2,4,3,3,3,1,3,2}; for (int i = 0; i < 14; i++) { if (cnt == 0) { cand = a[i]; cnt =…
- Dutch-national-flag partition on a = [2, 0, 1, 2, 1, 0, 0, 2, 1, 1, 0, 2]: lo = mid = 0, hi = 11; while mid <= hi: if a[mid] == 0 {…
- A heap with 2000 elements is stored in an array (complete binary tree, last level filled left to right). How many elements are in the left…