My issue
my output come in reverse form
My code
#include <stdio.h>
int main() {
int n;
// Input the number of elements
scanf("%d", &n);
int arr[n];
// Input the elements of the array
for (int i = 0; i < n; i++) {
scanf("%d",&arr[i]);
}
// Variable to track the maximum from the right
int max_from_right = arr[n - 1]; // The rightmost element is always a leader
printf("%d",max_from_right); // Print the rightmost leader
// Traverse the array from the second last element to the first
for (int i = n - 2; i >= 0; i--) {
if (arr[i] > max_from_right) {
max_from_right = arr[i];
printf("%d",max_from_right); // Print the new leader
}
}
return 0;
}
Learning course: BCS301: Data structures
Problem Link: https://www.codechef.com/learn/course/abesit-dsa/ABESITDS06/problems/DSAAGP11