Data Structures & AlgorithmsHardGATE CS · TCS NQT
A road of length 24 has fuel stations at kilometres 3, 7, 9, 14, 17, 22. The car starts at 0 and has range 8 km per tank (it refuels fully at each station). What is the minimum number of stations the car must stop at to reach km 24?
- A. 4
- B. 3
- C. 2
- D. 5
Correct answer: B. 3
Greedy: from the current position, go to the farthest station within range. Each jump counts one stop, and the final leg needs no extra refuel since the goal is reachable.
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
- Buildings of heights [4, 1, 6, 2, 5, 3] are viewed from the right. How many are visible (strictly taller than every building to their…
- What is the smallest positive integer m such that the sum of ceil(ai / m) over a = [7, 11, 12] is at most 9?
- How many ordered pairs (x, y) with 1 <= x, y <= 12 have x y divisible by 12?
- From the multiset [6, 1, 4, 2, 5, 3], choose as many elements as possible (order irrelevant) with total at most 10. What is the maximum…
- How many times does "ab" occur as a substring of the string "aab" repeated three times?
- How many distinct values arise as a sum of two different elements (by position) of [3, 5, 8, 10]?