1.(Evaluate Division) We have list of ratios of of different variables and query to find the result?
For example :
List is:
a/b = 1.0;
b/c = 2.0;
c/d = 3.0;
Query is :
a/d = ? (here answere is 6.0)
Write a program to return the query result. You may choose any data structure for input (I used array of DataSet as below) as you want.
Somethings like:
Method signature is like this:
public DataSet getQueryResult(DataSet[] input, Dataset query);
class DataSet{
String nominator; // a
String denominator; //b
float value; // 1.0
}
For Example :
X = 2 and Y = 5 following are the operations performed:
1st ops : 2 * 2 = 4
2nd ops : 4 - 1 = 3
3rd ops : 3 * 2 = 6
4th ops : 6 - 1 = 5
Hence return 4;
Note : There can be other many ways to reach 5 but above is the minimum operation amongst other. If NONE is found, return MAX_VALUE;