Cranes at VIIT Q1

Array Leader Finder

Write a C program that finds all the leaders in an integer array.

Definition of a Leader:

An element is called a leader if it is strictly greater than all the elements to its right. The rightmost element is always considered a leader.

Input Format:

Output Format:

Example Inputs & Outputs:

Enter the number of elements: 6
Enter the elements: 16 17 4 3 5 2
Leaders: 17 5 2
            
Enter the number of elements: 5
Enter the elements: 1 2 3 4 5
Leaders: 5
            

Constraints:

Hint:

Iterate from the end of the array and maintain a variable maxFromRight to track the maximum value encountered so far. Compare each element with maxFromRight and update it if the current element is a leader.

Bonus Challenge:

Optimize the solution to run in O(n) time.

Task: Write a program that implements this logic.