<p>You are given an integer array <code>nums</code> and an integer <code>x</code>. In one operation, you can either remove the leftmost or the rightmost element from the array <code>nums</code> and subtract its value from <code>x</code>. Note that this <strong>modifies</strong> the array for future operations.</p>
<p>Return <em>the <strong>minimum number</strong> of operations to reduce </em><code>x</code><em>to <strong>exactly</strong></em><code>0</code><em>if it is possible</em><em>, otherwise, return </em><code>-1</code>.</p>
<strong>Input:</strong> nums = [3,2,20,1,1,3], x = 10
<strong>Output:</strong> 5
<strong>Explanation:</strong> The optimal solution is to remove the last three elements and the first two elements (5 operations in total) to reduce x to zero.