Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS
Choose the fewest intervals of length 3 (covering integer points s, s+1, s+2 for a start s from 1 to 8) so that every integer point from 1 to 10 is covered. What is the minimum number of intervals?
- A. 5
- B. 3
- C. 6
- D. 4
Correct answer: D. 4
Greedy: place each interval as far right as possible while still covering the leftmost uncovered point. Ten points need at least ceil(10 / 3) = 4 intervals, and four suffice.
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 x with 1 ≤ x ≤ 2024 have NO two equal adjacent digits in their decimal representation?
- How many integers x with 1 ≤ x ≤ 500 have a decimal digit sum divisible by 3?
- You may swap the digits at exactly one pair of positions in the number 98368 (at most once). What is the largest number you can obtain?
- Children need greed factors [1, 2, 3, 5, 7]. Each child can receive at most one cookie, and a child is satisfied if the cookie size is at…
- In one move you may increase ALL but one element of the array [1, 2, 4, 7] by 1. What is the minimum number of moves to make all elements…
- Each move changes an element of [1, 2, 9, 10, 4, 4, 3] by exactly 1 (up or down). What is the minimum number of moves needed to make all…