Data Structures & AlgorithmsVery hardGATE CS · DSA
How many pairs (i < j) of [2, 15, 17, 10, 24, 2, 10, 2, 4, 9] have a[i] + a[j] divisible by 4? (Count remainders mod 4 and pair r with 4 − r.)
- A. 33
- B. 13
- C. 15
- D. 12
Correct answer: B. 13
Remainder counts: 0→2, 1→2, 2→5, 3→1. Pairs come from classes r and k − r (C(c, 2) when r = 0 or r = k/2). The total is 13; multiplying c[r]·c[k − r] over all r double-counts and mishandles the self-paired classes.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- A 2-D array A[0..11][0..29] of 2-byte elements is stored in column-major order starting at address 2000. What is the address of A[9][6]?
- For each day, a monotonic stack finds how many days you must wait for a strictly warmer temperature (0 if never). What is printed? python…
- Longest run of consecutive integers (in any order) using a hash set and starting only from numbers whose predecessor is absent. What is…
- Quickselect returns the k-th smallest element of an unsorted array in expected O(n) time. For [29, 18, 10, 32, 39, 19, 36, 13] and k = 4…
- A peak is an element larger than its neighbours (array ends count as −∞). Binary search runs on [43, 46, 49, 14, 48, 18, 24, 47, 28]…
- A fixed window of length 3 slides over s = "bcaacbccbbbbac" with a character-count array. At how many starting positions is the window an…