Data Structures & AlgorithmsVery hardGATE CS · CAT · MBA placement
How many arrays of length 4 with entries from {1, 2, ..., 3} are NON-INCREASING (each entry is at least the next)?
- A. 20
- B. 10
- C. 15
- D. 81
Correct answer: C. 15
A non-increasing array is determined by how many times each value is used, i.e. by a multiset of size n from m values: C(n + m − 1, n). Ordered tuples with a condition on adjacent pairs are exactly what this counts.
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
- Daily prices are [3, 2, 6, 5, 0, 3, 8, 1, 9]. You may complete at most 3 buy-then-sell transactions (one share at a time, sell before the…
- What is the maximum sum of a non-empty contiguous subarray of [4, -6, 3, -1, 7, -2, 5] that contains AT MOST one negative element?
- What is the maximum product of exactly 3 consecutive elements of [2, -3, 4, -1, 5, -6, 2]?
- How many contiguous subarrays (of length at least 2) of [1, 3, 4, 2, 5, 6, 8, 1] are strictly increasing?
- How many subarrays (i ≤ j) of [2, 1, 2, 3, 1, 2] have their first and last elements equal? A single element counts (its first and last are…
- Closed integer intervals are [(1, 4), (2, 6), (5, 9), (3, 3), (6, 8), (7, 12)]. What is the largest number of intervals that share a…