

Leaders in an Array | SDE Sheet | Arrays
source link: https://www.geeksforgeeks.org/videos/leaders-in-an-array-gatuto/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

- 70 Views
- 05/04/2022
In this video, we will discuss how to print all the LEADERS in the array. For an element to be considered as a LEADER it has to be greater than all the elements to its right or we can also say that all the elements to the right of the LEADER should be less than the LEADER. Also, the element at the rightmost position (the last element) is always a LEADER.
For example in the array [13,16,4,3,6,2], leaders are 16, 6 and 2.
We will be using two methods: 1) Method 1: We will take two loops. The outer loop will run from 0 to size-1, picking the elements one by one from the left. The inner loop will help us compare this picked element with all the elements coming after it (all the elements to it's right). The picked element is considered a LEADER if it is greater than all the elements to its right.
2) Method 2: We scan all the elements from right to left in an array and keep track of the maximum element. When the value of maximum changes, we print the value.
Practice Problem: https://practice.geeksforgeeks.org/problems/leaders-in-an-array-1587115620/1 Article: https://www.geeksforgeeks.org/leaders-in-an-array/ SDE Sheet: https://www.geeksforgeeks.org/sde-sheet-a-complete-guide-for-sde-preparation/
Recommend
-
5
Equilibrium pointEquilibrium point | SDE Sheet | ArraysVideo Player is loading.Loaded: 0%Remaining Time -0:00360 Views
-
8
Sort an array of 0s, 1s and 2sSort an array of 0s, 1s and 2s | SDE Sheet | ArrayVideo Player is loading.Loaded: 0%Remaining Time -0:00
-
6
Reverse array in groupsReverse array in groups | SDE Sheet | ArraysVideo Player is loading.Loaded: 0%Remaining Time -0:00120...
-
6
Missing number in arrayMissing number in array | SDE Sheet | ArraysVideo Player is loading.Loaded: 0%Remaining Time -0:0012/...
-
8
Kadane’s AlgorithmKadane’s Algorithm | SDE Sheet | ArraysVideo Player is loading.Loaded: 0%Remaining Time -0:00460 Views
-
12
Subarray with given sumSubarray with given sum | SDE Sheet | ArraysVideo Player is loading.Loaded: 0%Remaining Time -9:28280...
-
9
Trapping Rain WaterTrapping Rain Water | SDE Sheet | ArraysVideo Player is loading.Loaded: 0.48%00:00Remaining Time -10:19
-
8
Minimum PlatformsMinimum Platforms | SDE Sheet |ArraysHi. In this video, we will learn howLoaded: 0.68%00:01Remaining Ti...
-
9
Stock buy and sellStock buy and sell | SDE Sheet | ArraysVideo Player is loading.Loaded: 0%00:00Remaining Time -11:45
-
6
Largest subarray with 0 sumLargest subarray with 0 sum | SDE Sheet | ArraysVideo Player is loading.Loaded: 0%00:00Remaining Time -10:53...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK