Data Structures & AlgorithmsVery hardProduct placement · Amazon/Microsoft
How many pairs (i < j) of [6, 27, 29, 25, 10, 6, 25, 3, 7, 22] have a[i] + a[j] divisible by 6? (Count remainders mod 6 and pair r with 6 − r.)
- A. 7
- B. 14
- C. 4
- D. 5
Correct answer: D. 5
Remainder counts: 0→2, 1→3, 2→0, 3→2, 4→2, 5→1. Pairs come from classes r and k − r (C(c, 2) when r = 0 or r = k/2). The total is 5; 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 queue is built from two stacks: enqueue pushes onto IN; dequeue pops from OUT, first moving every element of IN onto OUT only when OUT…
- LSD radix sort (base 10, stable sort on each digit, units digit first) is applied to [148, 261, 414, 335, 678, 773, 321]. What is the list…
- Items P, Q, R, S, T, U are pushed onto an empty stack in this order, and a pop may happen at any time. Which pop order is NOT possible?
- How many contiguous subarrays of [7, 6, 8, 5, 9, 1, 1, 9, 1, 9] contain exactly 2 odd numbers? (Use exactly(k) = atMost(k) − atMost(k − 1).)
- Longest run of consecutive integers (in any order) using a hash set and starting only from numbers whose predecessor is absent. What is…
- What does this loop-counting code print? (Python) python n, c = 20, 0 i = 1 while i < n: j = i while j < n: c += 1 j = 2 i += 1 print(c)