{"id":"4d24ff4b-36bc-42cc-a45f-0f9be82367be","name":"Next Greater Element Ii","description":"Given a circular integer array nums (i.e., the next element of nums[nums.length - 1] is nums[0]), return the next greater number for every element in nums.","inputFormat":"Input is managed for you","outputFormat":"Output is managed for you","constraints":"1: 1 &lt;= nums.length &lt;= 10^4\r\n2: -10^9 &lt;= nums[i] &lt;= 10^9","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\n\nvector<int> nextGreaterElementII(vector<int> nums){\n //write your code here\n}\n\nint main(){\n int n;\n cin>>n;\n vector<int> nums(n, 0);\n for(int i =0; i < n; i++){\n cin>>nums[i];\n }\n vector<int> ans = nextGreaterElementII(nums);\n \n n = ans.size();\n cout<<n<<endl;\n for(int i = 0; i < ans.size(); i++){\n cout<<ans[i];\n cout<<endl;\n }\n return 0;\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n public static int[] nextGreaterElementII(int[] nums) {\r\n return null;\r\n }\r\n\r\n\r\n public static void main(String[] args) throws Exception {\r\n BufferedReader read = new BufferedReader(new InputStreamReader(System.in));\r\n\r\n int n = Integer.parseInt(read.readLine());\r\n int nums[] = new int[n];\r\n for(int i=0;i<n;i++){\r\n nums[i] = Integer.parseInt(read.readLine());\r\n }\r\n \r\n int ans[] = nextGreaterElementII(nums);\r\n\r\n n = ans.length;\r\n\r\n System.out.println(n);\r\n for(int e: ans){\r\n System.out.println(e);\r\n }\r\n \r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"3\r\n1\r\n2\r\n1","sampleOutput":"3\r\n2\r\n-1\r\n2\r\n","questionVideo":"https://www.youtube.com/embed/RkG94TvnUFs","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":"8c6022a5-8654-4226-918f-8110af738bd4","name":"Stacks For Intermediate","slug":"stacks-for-intermediate-688","type":0},{"id":"a1a7ba10-608d-449f-8ed3-ba0c817bcdd1","name":"Next Greater Element Ii","slug":"next-greater-element-ii","type":1}],"next":{"id":"327ccc32-679f-4f4b-b0a5-e7060fa509df","name":"Next Greater Element Ii MCQ","type":0,"slug":"next-greater-element-ii-mcq"},"prev":{"id":"470da5fe-a1b3-49fa-8cfd-e516686e7a5b","name":"Next Greater Element I Easy","type":3,"slug":"next-greater-element-i-easy"}}}

Next Greater Element Ii

Given a circular integer array nums (i.e., the next element of nums[nums.length - 1] is nums[0]), return the next greater number for every element in nums.

{"id":"4d24ff4b-36bc-42cc-a45f-0f9be82367be","name":"Next Greater Element Ii","description":"Given a circular integer array nums (i.e., the next element of nums[nums.length - 1] is nums[0]), return the next greater number for every element in nums.","inputFormat":"Input is managed for you","outputFormat":"Output is managed for you","constraints":"1: 1 &lt;= nums.length &lt;= 10^4\r\n2: -10^9 &lt;= nums[i] &lt;= 10^9","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\n\nvector<int> nextGreaterElementII(vector<int> nums){\n //write your code here\n}\n\nint main(){\n int n;\n cin>>n;\n vector<int> nums(n, 0);\n for(int i =0; i < n; i++){\n cin>>nums[i];\n }\n vector<int> ans = nextGreaterElementII(nums);\n \n n = ans.size();\n cout<<n<<endl;\n for(int i = 0; i < ans.size(); i++){\n cout<<ans[i];\n cout<<endl;\n }\n return 0;\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n public static int[] nextGreaterElementII(int[] nums) {\r\n return null;\r\n }\r\n\r\n\r\n public static void main(String[] args) throws Exception {\r\n BufferedReader read = new BufferedReader(new InputStreamReader(System.in));\r\n\r\n int n = Integer.parseInt(read.readLine());\r\n int nums[] = new int[n];\r\n for(int i=0;i<n;i++){\r\n nums[i] = Integer.parseInt(read.readLine());\r\n }\r\n \r\n int ans[] = nextGreaterElementII(nums);\r\n\r\n n = ans.length;\r\n\r\n System.out.println(n);\r\n for(int e: ans){\r\n System.out.println(e);\r\n }\r\n \r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"3\r\n1\r\n2\r\n1","sampleOutput":"3\r\n2\r\n-1\r\n2\r\n","questionVideo":"https://www.youtube.com/embed/RkG94TvnUFs","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":"8c6022a5-8654-4226-918f-8110af738bd4","name":"Stacks For Intermediate","slug":"stacks-for-intermediate-688","type":0},{"id":"a1a7ba10-608d-449f-8ed3-ba0c817bcdd1","name":"Next Greater Element Ii","slug":"next-greater-element-ii","type":1}],"next":{"id":"327ccc32-679f-4f4b-b0a5-e7060fa509df","name":"Next Greater Element Ii MCQ","type":0,"slug":"next-greater-element-ii-mcq"},"prev":{"id":"470da5fe-a1b3-49fa-8cfd-e516686e7a5b","name":"Next Greater Element I Easy","type":3,"slug":"next-greater-element-i-easy"}}}
plane

Editor


Loading...

Next Greater Element Ii

easy

Given a circular integer array nums (i.e., the next element of nums[nums.length - 1] is nums[0]), return the next greater number for every element in nums.

Constraints

1: 1 <= nums.length <= 10^4 2: -10^9 <= nums[i] <= 10^9

Format

Input

Input is managed for you

Output

Output is managed for you

Example

Sample Input

3 1 2 1

Sample Output

3 2 -1 2

Question Video

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode