Data Structures & AlgorithmsVery hardLeetCode-style · Codeforces Div2 C
A train makes three legs of lengths 1, 3 and 2 km. Each leg except the last must be finished in whole hours (a partial hour is rounded up), and the last leg can take a fraction of an hour. You must arrive within 6 hours. What is the minimum integer speed in km/h?
- A. 2
- B. 1
- C. 0
- D. 3
Correct answer: B. 1
Binary search the integer speed v: legs before the last cost ceil(d/v) whole hours and the last leg costs d/v. The total time is non-increasing in v, so the first feasible v is the answer. Rounding every leg up (including the last) overestimates the time.
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 indices i in [1, 7, 3, 6, 5, 6] have the sum of elements strictly left of i equal to the sum of elements strictly right of i?
- How many contiguous subarrays of [1, -1, 2, -2, 3, -3, 1] sum to exactly 1?
- How many contiguous subarrays of [2, 5, 1, 4, 3] have their maximum equal to the first or the last element of the subarray?
- How many disjoint intervals remain after merging all overlapping closed intervals in [(1,3),(2,6),(8,10),(15,18),(17,20),(6,7)]?…
- How many index triples i < j < k in [2, 3, 4, 5, 7, 10] can be the three sides of a non-degenerate triangle (sum of the two smaller sides…
- How many index pairs i < j in [3, 5, 6, 8, 1] satisfy a[i] + a[j] > a[i] XOR a[j]?