Data Structures & AlgorithmsVery hardAmazon OA · Arrays
How many pairs of positions (i < j) in [5, 3, 7, 9, 1, 2, 6, 10, 14, 4] have a[i] + a[j] divisible by 4?
- A. 12
- B. 10
- C. 14
- D. 16
Correct answer: A. 12
Residues mod 4: three 1s, two 3s, four 2s and one 0. Pairs 1+3 give 3 x 2 = 6, pairs of 2s give C(4,2) = 6, the single 0 pairs with none: 12.
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 greedy stack algorithm removes exactly 3 digits from the number string "1432219" to get the smallest possible number (keeping the order…
- A cache with 3 slots serves the page requests 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5. How many misses occur under LRU replacement and under…
- What is the time complexity of reading the element arr[i] from an array of n elements, given i?
- Which data structure works on the Last In, First Out (LIFO) principle?
- What is the worst-case time complexity of binary search on a sorted array of n elements?
- Which of these sorting algorithms is stable in its standard implementation?