c++ solution without using stack | beginner friendly
Intuition\n Describe your first thoughts on how to solve this problem. \ncreate a new array of double size of nums. so that we can iterate over the array twice\
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\ncreate a new array of double size of nums. so that we can iterate over the array twice\n# Approach\n<!-- Describe your approach to solving the problem. -->\niterate over the first n elements of temp and find the next greater element of each element if no greater element was found push back -1 to ans vector.\n# Complexity\n- Time complexity: O(N^2)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(N)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    vector<int> nextGreaterElements(vector<int>& nums) {\n        int n = nums.size();\n        vector<int> temp;\n        vector<int> ans;\n        temp = nums;\n        for(int i = 0; i < nums.size();i++){\n            temp.push_back(nums[i]);\n        }\n        for(int i = 0; i < n; i++){\n            int x = temp[i];\n            int j = i + 1;\n            while(j < temp.size()){\n                if(temp[j] > x){\n                    x = temp[j];\n                    break;\n                }\n                j++;\n            }\n            if(x != temp[i]) ans.push_back(x);\n            else ans.push_back(-1);\n        }\n        return ans;\n    }\n};\n```
['Array', 'C++']