Gas Station | Leetcode 134 | Greedy

แชร์
ฝัง
  • เผยแพร่เมื่อ 26 ม.ค. 2025

ความคิดเห็น • 21

  • @avisoft-l2p
    @avisoft-l2p 2 หลายเดือนก่อน +1

    we can manage it in single loop also!
    int canCompleteCircuit(vector& gas, vector& cost) {
    int start=0,totCost=0,totGas=0,cur=0;
    for(int i=0;i

  • @k.a.8399
    @k.a.8399 หลายเดือนก่อน

    I initially did the tot cost thinf but what i did was , took the diff and stored in gas[i] and then I check if sum of gas array is < 0 , I did this on my own and got amazed my original soln beat 15 % , but after video I got clicked that Oh, I do not need to check the whole circle if the previous indices are not ans , then upcoming must . Nice explanation .
    /*I have solved this question in O(n) but still it beats 15% , so I referred one yt video and to my surprise I brilliantly handled the edge case just that mine main loop needed a bit change .
    I was actually checking till cirucular loop if the ans is getting found , but the catch is that , for ex :
    firstly , we check whether the sum of diff

  • @RajeshS-n2j
    @RajeshS-n2j 3 หลายเดือนก่อน

    nice thing about your videos apart from solution is the introduction about problem statement and what is asked of the problem. thanks. 😀

    • @AyushiSharmaDSA
      @AyushiSharmaDSA  3 หลายเดือนก่อน

      Glad to hear that, welcom🤗

  • @Shubham-yc6nz
    @Shubham-yc6nz หลายเดือนก่อน

    Why does the for loop works? How can we guarentee that the case doesn't fail till gas.size -1?
    like what if the answer for first question was index = 4?

  • @akashkumardas1130
    @akashkumardas1130 2 หลายเดือนก่อน

    Thank you so much Ayushi for the explanation. Easily understood.
    total fuel < total cost is the game changer of the problem this idea is preety dificult to think about. After this line the problem is clear.

  • @Wonderfully_ok
    @Wonderfully_ok 3 ปีที่แล้ว

    Mam i would like to know how u managed college along with coding
    Plz make a separate vdo for that also about cgpa and attendance in class

  • @consistentthoughts826
    @consistentthoughts826 3 ปีที่แล้ว

    I think this is O(N^2) because for every index we have to calculate the whole array (looping)

    • @alphonseprakash7459
      @alphonseprakash7459 3 ปีที่แล้ว

      no it is o(N) we are changing the value of start but not the value of i

    • @sadashivshinde9150
      @sadashivshinde9150 3 ปีที่แล้ว

      if u want u can do the sum of gas and cost in same look and add a check before u return start

  • @sadashivshinde9150
    @sadashivshinde9150 3 ปีที่แล้ว

    I think it should be :
    .
    .
    .
    return start%size(gas);

  • @ToonDubberDuo
    @ToonDubberDuo 3 หลายเดือนก่อน

    the question was so confusing gosh :(

  • @mansigoyal4796
    @mansigoyal4796 3 ปีที่แล้ว

    Di waiting for the explanation video of today's question. (Stone Game IV)

    • @AyushiSharmaDSA
      @AyushiSharmaDSA  3 ปีที่แล้ว

      Yes Mansi, got delayed today :)

    • @mansigoyal4796
      @mansigoyal4796 3 ปีที่แล้ว

      No issues di. Upto what time I can expect.

    • @AyushiSharmaDSA
      @AyushiSharmaDSA  3 ปีที่แล้ว

      @@mansigoyal4796 uploaded :)

    • @mansigoyal4796
      @mansigoyal4796 3 ปีที่แล้ว

      Di your videos and easy explanations has made me consistent in doing leetcode. Thankyou so much.

    • @AyushiSharmaDSA
      @AyushiSharmaDSA  3 ปีที่แล้ว +1

      @@mansigoyal4796 thank you Mansi for kind words, your appreciation keeps me motivated :)

  • @unknownroads1
    @unknownroads1 3 ปีที่แล้ว +6

    Proof is unclear

  • @amandixit3555
    @amandixit3555 3 ปีที่แล้ว +1

    I think you didn't prove ur greedy solution correctly.