764. Find Distinct Expressions

Given an integer array nums, return all distinct values obtained by inserting mathematical ' + ' (addition) or ' - ' (subtraction) between each element of nums and evaluating the resulting expression.

Return the results in increasing order.

Example 1:

Input: nums = [1, 2, 3]

Output: [-4, 0, 2, 6]

Explanation: 1 + 2 + 3 = 6,

1 + 2 - 3 = 0,

1 - 2 + 3 = 2

1 - 2 - 3 = -4

Example 2:

Input: nums = [98, 71, 30]

Output: [-3, 57, 139, 199]

Explanation: 98 + 71 + 30 = 199

98 + 71 - 30 = 139

98 - 71 - 30 = -3

98 - 71 + 30 = 57

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 <= nums.length <= 10
  • 1 <= nums[i] <= 1000
0
class Solution {
public:
vector<int> distinctExpressions(vector<int>& nums) {
 
}
};
Test Case

Input:

Nums