Find Majority Element ( LeetCode #169 ) Part-1 | FREE DSA Course in JAVA | Lecture 76

preview_player
Показать описание
Let's solve a famous Leetcode question number 169 known as majority element question.

The program reads as -

Given an array of size n, return the majority element.

THe majority element is that element that appears more than [n/2] times. You may assume that majority element always exist.

Now in this part of the video, we'll check the naive appoach.

So we can use a simple logic. We can pick one element and count thew occurence fo that element using loops.

if the occurence is more than n/2 then we can return the element as majority element.

Let's see if this approach works by writing a program in Java.

But surely this apprach won't be the most efficient approach and hence why would compaines like Google, Meta, Amazon hire you?

We'll check another efficient approach in the part 2 of the lecture.

Stay tuned.

or call us at 8884881203

Рекомендации по теме
Комментарии
Автор

Sir mind blowing explanation, sir i watched many video's for this topics but i didn't understand anyone concept regarding this Question, when i watched your video, i understand logic instantly thank you very much sir . We need teacher like u, upload more videos sir on leetcode Q

piyushpandey
Автор

These teachers are putting such a great efforts to make us understand for free 🎉🎉 . Many many blessings to u people

great.Indian.culture
Автор

If you don't want to regret, skip the video

prashantjain
Автор

can this be done in less time complexity with one pass, not with 2 loops.
in short optimize the code

AffairWithGeo