Find Majority Element ( LeetCode

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

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

  • @Ben-xd7gy
    @Ben-xd7gy 10 หลายเดือนก่อน

    thank you so much sir....ur explanation needs a honor....by watching your fantastical explanation for first 5mins....i coded the solution...once again thanks sir

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

    Thank you sir....for such a beautifully explained optimal solution! Your content is really commendable....! Thanks a ton for the whole superb playlist , it's really helpful to me....!!

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

    Great way of explanation, I am beginner and for me this explanation with slow place and multiple time. Make me understand in more better way than other videos where they just take pen and paper and just walk through the program

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

    Great Explanation !! Thank You !! From this Explanation very helpful for me!!

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

    Great Explanation !! Thank you!

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

    what if the array is 6,6,3,3,4,3,2

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

      This code doesn’t work for all the test cases.

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

      This array doesn't have majority element because n=7 then majority element is greater than the 7/2 = 3 i.e element should appear more than the 3 times
      6-2 times
      3-3 times
      4-1 time
      2-1 time
      there is no element which appearing more than n/2 (>3)

    • @udaybhogi1836
      @udaybhogi1836 17 วันที่ผ่านมา

      @@SYD_Technologies this is the reason that every one tells us to read questions, as in the question it self mentioned that the majority element will be in the array

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

    It fails on multiple test cases😮😢

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

    Can this be a solution when there is majority element.
    1.sort an array (0(logn))
    2.int i=1
    While(in/2)
    Break;
    else
    Count=0;
    i++;
    }
    Return i-1;

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

      If there is not maj element then value of count will be 1 just use if at the end of loop if count ==1 return -1;

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

      if your sorting a array the efficient time complexity is O(nlogn)

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

    this is the code if no majority element:
    int maj=arr[0];
    int coun=1;
    for(int i=0;i