- 2

Write a program to print all the LEADERS in the array. An element is leader if it is greater than all the elements to its right

Write a program to print all the LEADERS in the array. An element is leader if it is greater than all the elements to its right side. And the rightmost element is always a leader. For example int the array {16, 19, 4, 3, 8, 3}, leaders are 19, 8 and 3? how to solved in c lenguage

11th Oct 2018, 2:42 AM
Golu
2 Respuestas
+ 2
I'm not going to spoil the process but, *nested for-loops*
11th Oct 2018, 2:48 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 2
You can look at any code that finds the maximum value in an array. You just need to change two things: yours needs to run backwards and whenever you find a new "leader", print it.
11th Oct 2018, 5:30 AM
Anna
Anna - avatar