Maximum Index | 03 July POTD | C++ | Geeks for Geeks Problem of the Day

แชร์
ฝัง
  • เผยแพร่เมื่อ 14 ต.ค. 2024

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

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

    Great explaination. It was hard to find video with simple explanation. Finally found this. Keep posting.

  • @beinghappy9223
    @beinghappy9223 ปีที่แล้ว

    excellent explanation sir

  • @deodattanewalkar7342
    @deodattanewalkar7342 ปีที่แล้ว

    please help with how to know it can be solved with sliding window technique

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

      Each technique has some requirements. If you feel that the question's constraints satisfy the requirements, you can try to use it.
      The way we have solved this problem here is similar to sliding windows but not an exact implementation of it. You must have figured out that we want to make the i and j pointers as far apart as possible so we are trying to move it right as much as possible. Whenever it contradicts our constraint we try to change the left pointer i and repeat the same process.
      Honestly, when it comes to choosing the right technique for a particular question it is more about intuition which comes with practicing questions. I can tell you why it can be solved with a sliding window but the identification part is something that comes with practice. You will be able to relate a new problem to older problems that you have solved when you solve a lot of them.

    • @ankitakhokhar7833
      @ankitakhokhar7833 7 หลายเดือนก่อน

      @@cpwithcppThankyou for the advice!

  • @nipamparmar3872
    @nipamparmar3872 ปีที่แล้ว

    We take j-i as our answer but it may be possible that arr[J]

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

      Yes you are correct and I have discussed the same example at 10:22

  • @abhijeetsingh8041
    @abhijeetsingh8041 ปีที่แล้ว

    how can we identify that it can be solved with sliding window ?

    • @deodattanewalkar7342
      @deodattanewalkar7342 ปีที่แล้ว

      +1

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

      Each technique has some requirements. If you feel that the question's constraints satisfy the requirements, you can try to use it.
      The way we have solved this problem here is similar to sliding windows but not an exact implementation of it. You must have figured out that we want to make the i and j pointers as far apart as possible so we are trying to move it right as much as possible. Whenever it contradicts our constraint we try to change the left pointer i and repeat the same process.
      Honestly, when it comes to choosing the right technique for a particular question it is more about intuition which comes with practicing questions. I can tell you why it can be solved with a sliding window but the identification part is something that comes with practice. You will be able to relate a new problem to older problems that you have solved when you solve a lot of them.

    • @abhijeetsingh8041
      @abhijeetsingh8041 ปีที่แล้ว

      @@cpwithcpp ok got it one doubt but constraint part plz eloborate that how we can connect contraints with sliding window technique?

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

      For example in this question sliding windows works in O(N) and the method we are using to check whether the conditions are satisfied or not is working in constant time. If the checking part was also O(N) then we could not have solved this question this way and the overall complexity would have been O(N ^ 2). This is what I meant by saying that we need to check whether our constraints allow us to do so or not.

    • @abhijeetsingh8041
      @abhijeetsingh8041 ปีที่แล้ว

      @@cpwithcpp ok thx

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

    the problem statement was very confusing and also very short, this problem should be labelled as Hard 😐

  • @aucostic_zone
    @aucostic_zone ปีที่แล้ว

    It's helpful 🎉thanks sir but I still don't understand.

  • @sauravchandra10
    @sauravchandra10 ปีที่แล้ว

    Bhai pls do dry runs taking examples

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

      Sure will keep that in mind.

    • @fffooccc9801
      @fffooccc9801 ปีที่แล้ว

      @@cpwithcpp i have a doubt ,i applied merge sort and at mergig function i added the required conditon, why it doesn't work there as I have seen similar types of questions done with this logoc,also please let me know whci qs can me done with merge sort code.

    • @bitmagic52
      @bitmagic52 ปีที่แล้ว

      @@cpwithcpp yes plz in the next video plz do dry run with at least one example