Leader in an Array (Code / Algorithm)

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

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

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

    thank you sir.your explanation is best explanations in whole youtube.

  • @Hemanthreddy-i1l
    @Hemanthreddy-i1l 8 หลายเดือนก่อน

    good explanation sir, you would take (i=size-1) in for loop to get correct in different test cases ,if you take size-2 first array will miss for some testcases

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

    The O(n) solution will pint the answer in reverse order which can lead to the Wrong answer, so a better way would be to store the answer in another array and print in reverse order :) BTW nice explanation!

  • @ArjunSingh-ef9oe
    @ArjunSingh-ef9oe ปีที่แล้ว

    very nice explaination sir

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

    Great work! Keep it up

  • @prachiyadav1611
    @prachiyadav1611 6 ปีที่แล้ว

    Is there any video on general tree ? (Trees)

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

    Sir, i think in the 2nd method that the condition is arr[i]>=mfr and the iteration start from n-1?

  • @gurmeetchawla8362
    @gurmeetchawla8362 6 ปีที่แล้ว

    hi vivekanand, if 16 is the rightmost element then what are your thoughts about this algo.

    • @santhuravikanti4988
      @santhuravikanti4988 6 ปีที่แล้ว

      i think if condition is not satisfied then mfr is the 16,please correct me if my understanding is wrong

  • @FrozenByTheSun
    @FrozenByTheSun 6 ปีที่แล้ว

    Thanks for the video. Your explanations are the best.
    Can you make one about external sorting? I can’t get it. I’ve sent you an email with the problem

  • @Ankit13555
    @Ankit13555 6 ปีที่แล้ว +2

    why dont we return the max element in array and last element in array.....please tell me where test cases will fail

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

      { 1 , 25 , 50 , 40 , 30 , 20 , 21 , 28 }
      here 50 is max and 28 is last element. Both are Leaders. But 30 is also the leader beacause all elements on right side of 30 are less than 30.

    • @vivekanandkhyade
      @vivekanandkhyade  6 ปีที่แล้ว

      Yes and 40 is also the leader.

    • @Ankit13555
      @Ankit13555 6 ปีที่แล้ว

      Vivekanand Khyade - Algorithm Every Day means only move from right to left is only way..... thankyou for clearing the doubt

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

    The actual question is: Given an array, print all the leaders.
    Now if we scan from the right and keep current max element, we can easily print the elements. Check out geeksforgeeks.

  • @atishnarlawar1177
    @atishnarlawar1177 6 ปีที่แล้ว

    Are you not just finding the max element in the array ?

  • @jaysahu357
    @jaysahu357 6 ปีที่แล้ว

    nice sir

  • @bhavadiph.gothadiya4026
    @bhavadiph.gothadiya4026 5 ปีที่แล้ว

    but here one problem in this solution
    if print all leader number in order , then we have to maintain the order of leader because this solution return leader number in reverse order,,

  • @9738803535
    @9738803535 5 ปีที่แล้ว

    In greeks for greeks for given below input they are looking for sequential output
    Example:
    Input array : 16 17 4 3 5 2
    Output : 17 5 2

    • @ganeshnanekar3764
      @ganeshnanekar3764 4 ปีที่แล้ว

      Just inverse an op... you'll get the write answer

    • @Hemanthreddy-i1l
      @Hemanthreddy-i1l 8 หลายเดือนก่อน

      for that u should take " for(i=size-1;i>=0;i--) " while doing logic

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

    Can you provide full code for this😣

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

    always try to run the code after explanation

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

    if(j==n){
    printf("Print the leader");// this needs to be outside the inner for loop
    }

  • @divyalakshmip925
    @divyalakshmip925 5 ปีที่แล้ว

    sir
    this method is not working for this input
    7 4 7 5 3
    it gives a o/p
    7 3
    but its actual o/p is
    7 7 3

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

      Its correct output should be 3, 5, 7 only

    • @letsexplorewith_jaggu98
      @letsexplorewith_jaggu98 4 ปีที่แล้ว

      @@anandjha5353 7 7 5 3 should be the answer sir

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

      @@letsexplorewith_jaggu98 An element is leader if it is greater than all the elements to its right side. So the output should be 7 5 3 only. If we are counting 7 two times then second seven is equal not greater to all its right element so this should not be included.

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

      @@anandjha5353 it's okay sir.. I just said included with duplicates too..
      I just remembered you that Divyalakshmi missed 5 in her answer.

    • @anandjha5353
      @anandjha5353 4 ปีที่แล้ว

      @@letsexplorewith_jaggu98 right bro 👍

  • @digitaltanzeel1056
    @digitaltanzeel1056 2 ปีที่แล้ว

    Can anyone code in python

  • @NCCSAyesha-st3hv
    @NCCSAyesha-st3hv 4 ปีที่แล้ว

    Fucking internet

  • @NCCSAyesha-st3hv
    @NCCSAyesha-st3hv 4 ปีที่แล้ว

    Patang Tu se