Data Structures & AlgorithmsHardCodeforces Div2 B · TCS NQT
The sorted numbers [1, 3, 6, 7, 10, 11, 15] must be split into the fewest CONTIGUOUS groups so that in each group the largest minus the smallest is at most 2. What is the minimum number of groups?
- A. 5
- B. 3
- C. 4
- D. 6
Correct answer: C. 4
Greedy from the left: start a group at the smallest unassigned number and extend while the range stays within D. Starting groups at fixed positions (blocks of equal size) fails when gaps between values are uneven.
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 arrays of length 3 with entries from {1, 2, ..., 3} have a maximum entry of exactly 2?
- 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…