Leetcode 871 Minimum Number of Refueling Stops ||Code + Example + Explanation ||June Daily Challenge

Sdílet
Vložit
  • čas přidán 11. 06. 2021
  • A car travels from a starting position to a destination which is target miles east of the starting position.
    Along the way, there are gas stations. Each station[i] represents a gas station that is station[i][0] miles east of the starting position, and has station[i][1] liters of gas.
    The car starts with an infinite tank of gas, which initially has startFuel liters of fuel in it. It uses 1 liter of gas per 1 mile that it drives.
    When the car reaches a gas station, it may stop and refuel, transferring all the gas from the station into the car.
    What is the least number of refueling stops the car must make in order to reach its destination? If it cannot reach the destination, return -1.
    Note that if the car reaches a gas station with 0 fuel left, the car can still refuel there. If the car reaches the destination with 0 fuel left, it is still considered to have arrived.
    Example 1:
    Input: target = 1, startFuel = 1, stations = []
    Output: 0
    Explanation: We can reach the target without refueling.
    Example 2:
    Input: target = 100, startFuel = 1, stations = [[10,100]]
    Output: -1
    Explanation: We can't reach the target (or even the first gas station).
    Example 3:
    Input: target = 100, startFuel = 10, stations = [[10,60],[20,30],[30,30],[60,40]]
    Output: 2
    Explanation:
    We start with 10 liters of fuel.
    We drive to position 10, expending 10 liters of fuel. We refuel from 0 liters to 60 liters of gas.
    Then, we drive from position 10 to position 60 (expending 50 liters of fuel),
    and refuel from 10 liters to 50 liters of gas. We then drive to and reach the target.
    We made 2 refueling stops along the way, so we return 2.
    Link to challenge :leetcode.com/problems/minimum...

Komentáře • 32

  • @RakeshKumar-ub3nt
    @RakeshKumar-ub3nt Před 2 lety +7

    Best explanation among all the available on CZcams for this problem. Great job!

  • @ChiragVithlani
    @ChiragVithlani Před rokem +1

    Thank you. Very nicely explained.
    We can think of this problem like we need to travel far away and we want to keep minimum number of stops.
    Every time fuel station comes we get "spare new empty fuel storage tank" and fill it ( imagine that doesn't count as stop as we are not filling vehicle but "spare new empty fuel storage tank" ).
    Now when our vehicle is empty; we get "spare fuel storage tank" with MAX fuel ( and we count how many such storage capacity fuel tank we use till we reach target).

  • @p25_rhythm70
    @p25_rhythm70 Před 20 dny

    Very good and on point explanation

  • @siddharthdwivedi3263
    @siddharthdwivedi3263 Před 2 lety +1

    Clear , concise and nice explanation!! Thank you!!

  • @pranavsharma7479
    @pranavsharma7479 Před 2 lety +5

    i did 150-200 problems but still struggle how to solve problems like these, any suggestions/tips for that please

  • @amolmishra8621
    @amolmishra8621 Před 3 lety

    Very good explanation. Am glad I came across this channel. Looks like a lot more content to explore as well.
    Keep up the good work!

  • @i_am_groot3787
    @i_am_groot3787 Před 3 dny

    nice explanation and code

  • @iamnoob7593
    @iamnoob7593 Před 22 dny

    brilliant alisha , Thank you

  • @maddycoder1294
    @maddycoder1294 Před rokem

    Just Love your Explanation

  • @divyanshuraj4085
    @divyanshuraj4085 Před 3 lety +2

    son/daughter for rich businessman xd , btw wonderfull explanation :)

  • @anujjain9353
    @anujjain9353 Před rokem

    Thank you for such a simple explanation..

  • @darshantripathi9454
    @darshantripathi9454 Před rokem

    Very Nice example given, I was in same doubt ,that why we are using previously unvisited stations. but now I completely understood👏👏👏

  • @dhruvpurwar6642
    @dhruvpurwar6642 Před 2 lety

    Great stuff!!

  • @AnshulThk
    @AnshulThk Před rokem

    Thank you, It was a great explanation

  • @anshukumari6226
    @anshukumari6226 Před rokem

    Nicely explained !! Thanks Alisha :)

  • @sumonchatterjee3340
    @sumonchatterjee3340 Před 2 lety

    loved the explanation.thanks a lot

  • @ankoor
    @ankoor Před 3 lety

    Good explanation!

  • @shubhamhire9390
    @shubhamhire9390 Před rokem +1

    Such a beautiful explanation, keep up the good work🔥🔥👌👌

  • @harshilgandhi2191
    @harshilgandhi2191 Před 6 měsíci

    such a beautiful and clear code with proper explanation

  • @tryingtomakesenseoftheverse

    best explanation on youtube🙌

  • @Kashish_Batra
    @Kashish_Batra Před rokem

    great explanation :)

  • @reshmamaam1451
    @reshmamaam1451 Před 3 lety

    Very good 💯

  • @sajalgupta3553
    @sajalgupta3553 Před rokem

    nice explanation... keep it up :)

  • @shubhamsukum
    @shubhamsukum Před rokem

    THanks

  • @meershahidmanzoor
    @meershahidmanzoor Před 2 lety

    But we have to take a note of our location where we have reached as well as of the location of the filling stations

  • @gorakhkumargupta491
    @gorakhkumargupta491 Před 2 lety

    Thank you ma'am

  • @sagarbora7768
    @sagarbora7768 Před rokem

    ALisha Ur explanation skills are 😍

  • @maharajak6578
    @maharajak6578 Před 3 lety +1

    best explanation available for this question so far.

  • @rbrohitbisht
    @rbrohitbisht Před rokem

    Not sure how did you reach point 30 from 60.. it is mentioned, move towards east.. not east to west.. one directional..🤓

  • @its_me_hb
    @its_me_hb Před rokem

  • @shvmsh20
    @shvmsh20 Před rokem

    Uh made it so simple

  • @Thescienceworld652
    @Thescienceworld652 Před rokem

    wow , i have written the exact code like u ... but my code is not running after that i came here .