Please solve the programming task below using a self-contained code snippet in a markdown code block.

You are given an integer array nums and an integer x. In one operation, you can either remove the leftmost or the rightmost element from the array nums and subtract its value from x. Note that this modifies the array for future operations.
Return the minimum number of operations to reduce x to exactly 0 if it is possible, otherwise, return -1.
 
Please complete the following python code precisely:
```python
class Solution:
    def minOperations(self, nums: List[int], x: int) -> int:
```