You are given an array with integer elements. Give the next greatest element for every index of the array.
For each position, return the first strictly greater value to its right, or -1 if no such value exists. Implement next_greater_elements(nums), which accepts a list of integers and returns a list of equal length.
Example: nums = [4, 5, 2, 10, 8] produces [5, 10, 10, -1, -1]. Equal values do not qualify as greater. Constraints: 1 <= len(nums) <= 1000 and -10^9 <= nums[i] <= 10^9.
def next_greater_elements(nums):