• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
January 23, 2024 |1.5K Views
SDE Sheet - Circular tour
  Share   Like
Description
Discussion

This video is part of Stack and Queue section under GFG SDE Sheet.

In this problem, Suppose there is a circle. There are N petrol pumps on that circle. You will be given two sets of data.
1. The amount of petrol that every petrol pump has.
2. Distance from that petrol pump to the next petrol pump.
Find a starting point where the truck can start to get through the complete circle without exhausting its petrol in between.
Note :  Assume for 1 litre petrol, the truck can go 1 unit of distance.

Example :

Input:
N = 4
Petrol = 4 6 7 4
Distance = 6 5 3 5
Output: 1

Explanation: There are 4 petrol pumps withamount of petrol and distance to nextpetrol pump value pairs as {4, 6}, {6, 5}, {7, 3} and {4,5}. The first point from where truck can make a circular tour is 2nd petrol pump. Output in this case is 1 (index of 2nd petrol pump).

Try it out before watching the implementation of the problem in the video. We recommend watching the video, even if you can solve the problem. You may discover something new. All the best!!!

Do check out:-
Article: https://www.geeksforgeeks.org/find-a-tour-that-visits-all-stations/
Problem: https://www.geeksforgeeks.org/problems/circular-tour-1587115620/1
SDE Sheet Link: https://www.geeksforgeeks.org/sde-sheet-a-complete-guide-for-sde-preparation/

Read More