Posts

Showing posts from October, 2022

Find the Leader C++

  #include<bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int arr[n]; int i; for (i = 0; i < n; i++) { cin >> arr[i]; } int max = arr[n - 1]; cout << arr[n - 1] << " "; for (i = n - 2; i >= 0; i--) { if (arr[i] >= max) { max = arr[i]; cout << max << " "; } } cout << '\n'; } return 0; }