Problem Statement
You are given an int y.
We are looking for any int[] x that satisfies the following constraints:
If there are multiple valid solutions, you may return any of them. You may assume that for our constraints on y (specified below) at least one valid x always exists.
- x has exactly three elements
- ( x[0] * x[1] ) + x[2] = y
- Each x[i] must be between -1000 and 1000, inclusive.
- No x[i] can be equal to 0 or 1.
If there are multiple valid solutions, you may return any of them. You may assume that for our constraints on y (specified below) at least one valid x always exists.
Definition
- Class:
- AddMultiply
- Method:
- makeExpression
- Parameters:
- int
- Returns:
- int[]
- Method signature:
- int[] makeExpression(int y)
- (be sure your method is public)
Constraints
- y will be between 0 and 500, inclusive.
Examples
6
Returns: {2, 2, 2 }2*2 + 2 = 6 Note that this is one of many possible solutions. Another solution is: 3*3 + (-3) = 611
Returns: {2, 3, 5 }0
Returns: {7, 10, -70 }Note that 0 and 1 are not allowed, thus a result like 0 * 0 + 0 would be incorrect.500
Returns: {-400, -3, -700 }Some or all of the returned numbers may be negative.2
Returns: {2, 2, -2 }5
Returns: {5, 2, -5 }