GATE Computer ScienceModerateGATE CS (PYQ pattern)
How many index pairs i < j satisfy a[i] + a[j] == 10 in the array {3, 8, 5, 2, 7, 4, 6, 1, 9, 5, 3, 7}?
- A. 6
- B. 10
- C. 8
- D. 12
Correct answer: C. 8
Count by value: (3,7): two 3s and two 7s give 4 pairs; (8,2): 1; (4,6): 1; (1,9): 1; (5,5): 1 pair from two 5s: total 8.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- unsigned x = 0x369; / binary 11 0110 1001 / unsigned s = 0, c = 0; while (x) { unsigned t = x & -x; c++; s += t c; x -= t; } What is s…
- int a[3][4] = {{3,1,4,1},{5,9,2,6},{5,3,5,8}}; int t = 0; for (int j = 0; j < 4; j++) for (int i = 0; i < 3; i++) t += ((a + i) + j) (j +…
- A queue is a circular array that starts with capacity 4 and doubles (copying every element) when an enqueue finds it full; dequeues never…
- unsigned char x = 0x5B; unsigned s = 0; for (int i = 0; i < 6; i++) { x ^= (unsigned char)(x << 3); x ^= x >> 2; s += x; } printf("%u %u"…
- A bracket checker pushes every opening bracket and, on a closing bracket, pops and compares. For the string {[()()]([{}])}[({[]}) the…
- A queue holds 5, 12, 7, 3, 9, 14, 2, 8 (front first). To reverse the first 5 elements, they are dequeued onto a stack, popped back and…