Problem Statement |
| You will be given an equation of the form <side>=<side> where <side> is a list of <term>s separated by <op>s. Each <op> is either + or -, and each <term> is a positive length string of uppercase letters. Each letter denotes a variable taking on real values. No letter will occur in a <term> more than twice.
The <term>s are products of variables. As you would expect, the + and - operators take lower precedence than the multiplications within the <term>s. For example,
ABC+ADF=PQ-PQ
is a properly formatted equation. Sometimes, by fixing a single variable at a particular value, we can force the entire equation to always be true. Return a String[] containing all such variables that satisfy this requirement. If a variable can be set to n distinct values all of which satisfy this requirement, then that variable should occur n times in the return. If a variable can be set to an infinite number of distinct values that satisfy this requirement, it should not be returned. The return should be sorted in alphabetical order. |
|
Definition |
| Class: | VariableSolve | Method: | getSolutions | Parameters: | String | Returns: | String[] | Method signature: | String[] getSolutions(String equation) | (be sure your method is public) |
|
|
|
|
Constraints |
- | equation will contain between 3 and 50 characters inclusive. |
- | equation will be formatted as described in the problem statement. |
|
Examples |
0) | |
| | Returns: {"N", "P" } | Simpler than it looks: let N = 1 or P = 0. |
|
|
1) | |
| | Returns: {"E" } | Only E = 0 guarantees the equation holds. |
|
|
2) | |
| | Returns: { } | Each variable has an infinite number of values causing the equation to hold. |
|
|
3) | |
| | Returns: {"B" } | We cannot consider the complex solutions for A. |
|
|
4) | |
| |