Data Structures & AlgorithmsHardGATE CS · TCS NQT
How many arrays of length 3 with entries from {1, 2, ..., 3} have a maximum entry of exactly 2?
- A. 15
- B. 3
- C. 27
- D. 7
Correct answer: D. 7
Count arrays with all entries ≤ k minus arrays with all entries ≤ k − 1: that is k^n − (k−1)^n. Counting arrays that contain k at least once with a single placement of k overcounts.
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 non-empty subsets of [4, 6, 9, 10, 15] (chosen by position) have a greatest common divisor equal to 1?
- What is the length of the longest contiguous subarray of [2, -3, 0, -1, 4, -2, 5, -1] whose product is strictly positive?
- Let P[0] = 0 and P[k] be the XOR of the first k elements of [3, 5, 6, 3, 1, 5, 2]. How many pairs of indices (i < j) among 0..7 have P[i]…
- In how many ways can the binary string "0110100110" be cut into one or more contiguous segments so that every segment contains equally…
- Among all arrangements reachable from [4, 2, 1, 3] by swapping ONE pair of adjacent elements (or by doing nothing), what is the minimum…
- What is the minimum number of single-character flips needed to make "1101001011" alternate (no two adjacent characters equal)?