{"id":"8d25dca0-e76a-47e8-9bd2-8e5d7ea194bd","name":"Leaders In An Array","description":"Given an array A of positive integers. Your task is to find the leaders in the array. An element of array is leader if it is greater than or equal to all the elements to its right side. The rightmost element is always a leader. \r\n","inputFormat":"Input is managed for you\r\n","outputFormat":"Output is managed for you\r\n","constraints":"1 &lt;= n &lt;= 10^7\r\n0 &lt;= Ai &lt;= 10^7","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\n\nusing namespace std;\n\nvector<int> leaders(vector<int> &arr){\n // write your code here\n}\n\nint main() {\n int n;\n cin >> n;\n vector<int> arr(n, 0);\n for(int i = 0; i < arr.size(); i++){\n cin >> arr[i];\n }\n \n vector<int> ans = leaders(arr);\n \n for(int i = 0; i < ans.size(); i++){\n cout << ans[i] << \" \";\n }\n \n return 0;\n}"},"java":{"code":"import java.util.*;\r\nimport java.io.*;\r\n\r\npublic class Main {\r\n\r\n public static ArrayList<Integer> leaders(int[]arr) {\r\n\r\n }\r\n\r\n public static void main(String[]args) {\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n int[]arr = new int[n];\r\n\r\n for (int i = 0; i < n; i++) {\r\n arr[i] = scn.nextInt();\r\n }\r\n\r\n ArrayList<Integer>ans = leaders(arr);\r\n\r\n for (int val : ans) {\r\n System.out.print(val + \" \");\r\n }\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"6\r\n16 17 4 3 5 2","sampleOutput":"17 5 2","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"cb36811c-9cd7-4d80-aa52-ae9b8409862a","name":"Searching And Sorting For Intermediate","slug":"searching-and-sorting-for-intermediate-10001","type":0},{"id":"b6bdc92a-a3d0-401c-aef2-40440d643fa7","name":"Leaders In An Array","slug":"leaders-in-an-array","type":1}],"next":{"id":"ec4a451d-c8e8-4730-9412-7fcf788beb81","name":"Leaders In An Array","type":3,"slug":"leaders-in-an-array"},"prev":{"id":"21af76d0-60a5-41f5-b991-a3d6d3b322b0","name":"Punish The Students MCQ","type":0,"slug":"punish-the-students-mcq"}}}

Leaders In An Array

Given an array A of positive integers. Your task is to find the leaders in the array. An element of array is leader if it is greater than or equal to all the elements to its right side. The rightmost element is always a leader.

{"id":"8d25dca0-e76a-47e8-9bd2-8e5d7ea194bd","name":"Leaders In An Array","description":"Given an array A of positive integers. Your task is to find the leaders in the array. An element of array is leader if it is greater than or equal to all the elements to its right side. The rightmost element is always a leader. \r\n","inputFormat":"Input is managed for you\r\n","outputFormat":"Output is managed for you\r\n","constraints":"1 &lt;= n &lt;= 10^7\r\n0 &lt;= Ai &lt;= 10^7","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\n\nusing namespace std;\n\nvector<int> leaders(vector<int> &arr){\n // write your code here\n}\n\nint main() {\n int n;\n cin >> n;\n vector<int> arr(n, 0);\n for(int i = 0; i < arr.size(); i++){\n cin >> arr[i];\n }\n \n vector<int> ans = leaders(arr);\n \n for(int i = 0; i < ans.size(); i++){\n cout << ans[i] << \" \";\n }\n \n return 0;\n}"},"java":{"code":"import java.util.*;\r\nimport java.io.*;\r\n\r\npublic class Main {\r\n\r\n public static ArrayList<Integer> leaders(int[]arr) {\r\n\r\n }\r\n\r\n public static void main(String[]args) {\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n int[]arr = new int[n];\r\n\r\n for (int i = 0; i < n; i++) {\r\n arr[i] = scn.nextInt();\r\n }\r\n\r\n ArrayList<Integer>ans = leaders(arr);\r\n\r\n for (int val : ans) {\r\n System.out.print(val + \" \");\r\n }\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"6\r\n16 17 4 3 5 2","sampleOutput":"17 5 2","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"cb36811c-9cd7-4d80-aa52-ae9b8409862a","name":"Searching And Sorting For Intermediate","slug":"searching-and-sorting-for-intermediate-10001","type":0},{"id":"b6bdc92a-a3d0-401c-aef2-40440d643fa7","name":"Leaders In An Array","slug":"leaders-in-an-array","type":1}],"next":{"id":"ec4a451d-c8e8-4730-9412-7fcf788beb81","name":"Leaders In An Array","type":3,"slug":"leaders-in-an-array"},"prev":{"id":"21af76d0-60a5-41f5-b991-a3d6d3b322b0","name":"Punish The Students MCQ","type":0,"slug":"punish-the-students-mcq"}}}
plane

Editor


Loading...

Leaders In An Array

easy

Given an array A of positive integers. Your task is to find the leaders in the array. An element of array is leader if it is greater than or equal to all the elements to its right side. The rightmost element is always a leader.

Constraints

1 <= n <= 10^7 0 <= Ai <= 10^7

Format

Input

Input is managed for you

Output

Output is managed for you

Example

Sample Input

6 16 17 4 3 5 2

Sample Output

17 5 2

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode