Leader in an Array (Code / Algorithm)

  Рет қаралды 21,594

Vivekanand Khyade - Algorithm Every Day

Vivekanand Khyade - Algorithm Every Day

Күн бұрын

Пікірлер: 39
@Amitakd2023
@Amitakd2023 Жыл бұрын
thank you sir.your explanation is best explanations in whole youtube.
@KomalSinghbooks
@KomalSinghbooks 6 жыл бұрын
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!
@Hemanthreddy-i1l
@Hemanthreddy-i1l 11 ай бұрын
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
@ArjunSingh-ef9oe
@ArjunSingh-ef9oe Жыл бұрын
very nice explaination sir
@BECSAQUIB
@BECSAQUIB 3 жыл бұрын
Great work! Keep it up
@bqrkhn
@bqrkhn 6 жыл бұрын
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.
@Ankit13555
@Ankit13555 7 жыл бұрын
why dont we return the max element in array and last element in array.....please tell me where test cases will fail
@vivekanandkhyade
@vivekanandkhyade 7 жыл бұрын
{ 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 7 жыл бұрын
Yes and 40 is also the leader.
@Ankit13555
@Ankit13555 7 жыл бұрын
Vivekanand Khyade - Algorithm Every Day means only move from right to left is only way..... thankyou for clearing the doubt
@khaledhariz6320
@khaledhariz6320 4 жыл бұрын
Sir, i think in the 2nd method that the condition is arr[i]>=mfr and the iteration start from n-1?
@prachiyadav1611
@prachiyadav1611 6 жыл бұрын
Is there any video on general tree ? (Trees)
@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
@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,,
@shivprachigupta7124
@shivprachigupta7124 3 жыл бұрын
Can you provide full code for this😣
@shivprachigupta7124
@shivprachigupta7124 3 жыл бұрын
Showing 0 leader...
@shivprachigupta7124
@shivprachigupta7124 3 жыл бұрын
After i input values
@atishnarlawar1177
@atishnarlawar1177 7 жыл бұрын
Are you not just finding the max element in the array ?
@pradipkumardas1738
@pradipkumardas1738 5 жыл бұрын
always try to run the code after explanation
@suhailmir832
@suhailmir832 7 жыл бұрын
if(j==n){ printf("Print the leader");// this needs to be outside the inner for loop }
@shivprachigupta7124
@shivprachigupta7124 3 жыл бұрын
Show 0 leader... while run
@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 11 ай бұрын
for that u should take " for(i=size-1;i>=0;i--) " while doing logic
@FrozenByTheSun
@FrozenByTheSun 7 жыл бұрын
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
@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 жыл бұрын
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 жыл бұрын
@@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 жыл бұрын
@@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 👍
@jaysahu357
@jaysahu357 7 жыл бұрын
nice sir
@digitaltanzeel1056
@digitaltanzeel1056 2 жыл бұрын
Can anyone code in python
@NCCSAyesha-st3hv
@NCCSAyesha-st3hv 4 жыл бұрын
Fucking internet
@NCCSAyesha-st3hv
@NCCSAyesha-st3hv 4 жыл бұрын
Patang Tu se
Majority Element in an array (Algorithm)
4:12
Vivekanand Khyade - Algorithm Every Day
Рет қаралды 21 М.
Equilibrium Element in Array in  o(n) time complexity ( Interview Question for FAANG companies)
13:57
Vivekanand Khyade - Algorithm Every Day
Рет қаралды 9 М.
IL'HAN - Qalqam | Official Music Video
03:17
Ilhan Ihsanov
Рет қаралды 700 М.
“Don’t stop the chances.”
00:44
ISSEI / いっせい
Рет қаралды 62 МЛН
Remove Duplicates from sorted Array
21:22
Vivekanand Khyade - Algorithm Every Day
Рет қаралды 177 М.
Minimum jumps to reach end of array (Dynamic Programming)
26:46
Vivekanand Khyade - Algorithm Every Day
Рет қаралды 85 М.
Leaders in an Array | Brute - Optimal | Strivers A2Z DSA Course
11:53
take U forward
Рет қаралды 164 М.
Print Matrix Diagonally (Diagonal order)
13:22
Vivekanand Khyade - Algorithm Every Day
Рет қаралды 112 М.
3.4 Huffman Coding - Greedy Method
17:44
Abdul Bari
Рет қаралды 1,7 МЛН
Maximum Sum SubArray (Kadane's algorithm) (Largest Sum Contigous SubArray)
17:30
Vivekanand Khyade - Algorithm Every Day
Рет қаралды 93 М.
Stock Span Problem ALGORITHM ( Simplest explanation on Internet )
31:33
Vivekanand Khyade - Algorithm Every Day
Рет қаралды 988
How To Find All The Leaders In An Integer Array?
12:49
Naveen AutomationLabs
Рет қаралды 6 М.
Search an element in sorted and rotated array( Find PIVOT)
25:39
Vivekanand Khyade - Algorithm Every Day
Рет қаралды 29 М.