Data Structures & AlgorithmsHardGATE CS · ICPC regional
How many index triples i < j < k in the array [1, 2, 3, 4, 5, 6] have a[i] + a[j] + a[k] divisible by 5?
- A. 6
- B. 1
- C. 4
- D. 8
Correct answer: C. 4
Count residues mod 5 and combine residue classes whose sums are 0 mod 5 (for example 0+0+0, or 1+2+2). Counting by values alone is slower and error-prone.
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 has capacity 4 and an enqueue into a full queue is rejected. Operations in order: enqueue 1, 2, 3, 4; dequeue; dequeue; enqueue 5…
- What is the sum of the maxima of every contiguous window of size 3 in the array [1, 3, -1, -3, 5, 3, 6, 7]?
- How many valid sequences of 4 push and 4 pop operations are there on an initially empty stack, where every pop is applied only to a…
- Three processes arrive at time 0 with CPU bursts 5, 3 and 8. Round-robin scheduling uses a time quantum of 2, a process that is not…
- Remove exactly 3 digits from the number 1432219 (without reordering the rest) so that the remaining number is as small as possible. What…
- Repeatedly delete any two adjacent equal characters from the string abbacbaca until no such pair exists. How many characters remain?