Data Structures & AlgorithmsModerateICPC regional · Amazon SDE OA
From [1, 2, 2, 3, 5, 6, 6], what is the maximum number of disjoint pairs where the two values differ by at most 1?
- A. 4
- B. 2
- C. 3
- D. 5
Correct answer: C. 3
Sort the values and pair neighbours greedily, skipping a value that cannot pair with its successor. The disjoint pairs (1,2), (2,3) and (5,6) give three.
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
- How many integers from 1 to 64 inclusive have a binary representation (without leading zeros) that reads the same forwards and backwards?
- What is the minimum number of characters that must be inserted anywhere in "abcb" to make it a palindrome?
- How many windows of size 4 in [1, 2, 1, 3, 4, 2, 5, 6] contain four pairwise distinct values?
- What is the smallest positive integer n such that n! ends in exactly 10 trailing zeros?
- Items [1, 1, 1, 1, 2, 2, 3] must be placed into stacks of capacity 3 such that each stack holds only identical items. What is the minimum…
- How many index pairs i < j in [0, 1, 2, 3, 4] satisfy a[i] + a[j] = a[i] a[j]?