An element of a list is called a "leader" if every element to its right (and not just the one immediately to its right) is strictly smaller than it. By this definition, the last element of the list is automatically a leader.
Example: list_leaders([42, 7, 12, 5, 2, 9]) returns [42, 12, 9] (because 42 > all other numbers to its right, 7 no, 12 > all numbers to its right, etc.)
Complete the function list_leaders(L) which returns the list containing only the leader elements (in the same order as in L).
Solution Stats
Solution Comments
Show comments
Loading...
Problem Recent Solvers13
Suggested Problems
-
Find the peak 3n+1 sequence value
2565 Solvers
-
Increment a number, given its digits
682 Solvers
-
186 Solvers
-
Return the first and last characters of a character array
11795 Solvers
-
Replace every 3rd element in a vector with 4
263 Solvers
More from this Author53
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!