Data Structures & AlgorithmsVery hardCodeforces Div2 B-D · ICPC regional
Around a circular route, station i has gas[i] fuel and the trip to station i+1 costs cost[i]. With gas = [1, 2, 3, 4, 5] and cost = [3, 4, 5, 1, 2], starting from which station (0-indexed) can you complete the full circle?
- A. 3
- B. 0
- C. 4
- D. 2
Correct answer: A. 3
Station 0 has net gas -2 at its first step, so the tank goes negative at once. Starting at station 3 keeps the tank non-negative all the way around.
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
- In one move you may increment all elements of an array except one by 1. What is the minimum number of moves to make all elements of [1, 5…
- Two arrays a = [1, 3, 5] and b = [2, 4, 6] are given. You may reorder b arbitrarily and pair a[i] with the i-th element of the reordered…
- How many DISTINCT values v exist such that both v and v + 3 appear in [1, 5, 3, 4, 2, 4, 6, 1]? (Count distinct pair values, not index…
- What is the sum of Hamming distances (number of differing bit positions) over all unordered pairs of [1, 3, 5, 7]?
- In [12, 4, 12, 4, 12, 4, 9] every value appears three times except one value that appears once. Which value appears once?
- What is the maximum value of a[i] XOR a[j] over index pairs i < j in [3, 10, 5, 25, 2, 8]?