Amazon in-house interview question for SDE-II
1126

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
}

  1. (Broken Calculator) Write a program which will return minimum number of operation to reach from X to Y by using following operations:
    1. Multiply by 2 (two).
    1. Substract by 1 (one).

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;

Comments (3)