Created
December 4, 2019 13:18
-
-
Save mk6619/3949329dbd39fa35921612e9f35c82ab to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| using namespace std; | |
| int main() { | |
| //code | |
| int testCases; | |
| cin>>testCases; | |
| for(int i = 0 ; i < testCases; i++) { | |
| int n; | |
| cin>>n; | |
| int arr[n]; | |
| for(int j =0 ; j < n ; j++) { | |
| cin>>arr[j]; | |
| } | |
| int count = n-2; | |
| int arr_m[n]; | |
| arr_m[n-1] = arr[n-1]; | |
| int maxElement = arr[n-1]; | |
| for(int j =n-2 ; j >= 0 ; j--) { | |
| if(arr[j] >= maxElement) { | |
| arr_m[count] = arr[j]; | |
| count--; | |
| maxElement = arr[j]; | |
| } | |
| } | |
| for(int k = count+1; k < n; k++){ | |
| cout<<arr_m[k]<<" "; | |
| } | |
| cout<<endl; | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment