## Amazon Interview Question for Software Engineer / Developers

• 0

Country: India
Interview Type: In-Person

Comment hidden because of low score. Click to expand.
1
of 1 vote

Resistance between which two points? I would think that's rather relevant.

Comment hidden because of low score. Click to expand.
0

you have to just find the total_resistance...

Comment hidden because of low score. Click to expand.
0

my be interviewer want b/t A to D

Comment hidden because of low score. Click to expand.
0
of 0 vote

it can be solved using weighted graph in O(n) -- where n is number of edges

but i have stuck at this case:
AB = 5
BC = 10
CD = 5
AC = 5
BD = 5
how will you solve it theoretically ??

Comment hidden because of low score. Click to expand.
0

for the case given by ninja, i am giving an overview:

here where BC is repeated
means you have to update graph['B']['C'] using ohm's law(1/r = 1/r1 + 1/r2)

now graph[B][C] = 3.15
now add graph[B][C] and graph[C][D] , and store in graph[B][D] which is 8.15
now add graph[A][B] and graph[B][D] and store in graph [A][D] which is 13.15..

Comment hidden because of low score. Click to expand.
0

How about storing the information ? if we store the resultant resistance , we lose the information about the parallel resistances ?

Comment hidden because of low score. Click to expand.
0

@nachi: they havent asked about retrieving the data.. no need to store the input till the end of the process..

here they have asked ,"to find the total resistance how will you store(in which data structure) and calculate"...

Comment hidden because of low score. Click to expand.
0

Matrix is not a good idea because if I give you 100 nodes and 99 resistance in series, you get a 100x100 matrix with a lot of zeros.

I don't know how to explain in few words without writing code but one way is "topological sort". At each node, have a variable named oneByResistance

oneByResistance = 1/(1/(oneByResistanceOfParent) + edgeResistance) (For root oneByResistanceOfParent should not be added).

Process the whole graph and final resistance is 1/(OneByResistance) of last node processed. Hope this helps

Comment hidden because of low score. Click to expand.
0

@cobra In that case, you will have to check if AB*CD = AC*BD. If it is then no current would flow between BC (bridge circuit) and you can neglect that edge in graph.
But that's a specific case. Can't think of anything in general.

Comment hidden because of low score. Click to expand.
0

The general approach to solving a circuit problem is to use Kirchoff's laws. But this is way too sophisticated for an interview.

Comment hidden because of low score. Click to expand.
0

@eugene: Not so sure.

The purpose of an interview is not always to get a solution out of the candidate...

It is also possible that the candidate has an elec eng background, the position calls for it (software position in hardware team?) etc...

Of course, it is also possible that people are trying to get their homework done, and amazon happens to be the first company in the drop-down.

Comment hidden because of low score. Click to expand.
0
of 0 vote

Do we have to take care of The Bridge Circuit?

Comment hidden because of low score. Click to expand.
0

In the followin case, how a linked list will work
AB=5
BC=10
BD=30
CD=20

Resistance between A and D.
For this case we will need to next pointers from B.

Comment hidden because of low score. Click to expand.
0
of 0 vote

use linkList to store the value of resistance as node.
If same node is access twice then change its value to the resultant resistance obtained by 1/1\rprev+1\rcurr.

Comment hidden because of low score. Click to expand.
0
of 0 vote

why not use a hash table.
key is your route "a-b' or "cd"
value is list of parallel resitances

Comment hidden because of low score. Click to expand.
0

Can you elaborate more on your hash approach

Comment hidden because of low score. Click to expand.
0
of 0 vote

``````public class Resistance{

public static void main(String[] args){
HashMap <String, Double> resistances = new HashMap<String, Double>();

Double val = addResistance("AB", 0.1, resistances);
Double val2 = addResistance("AB", 0.1, resistances);
Double totalResistance = computeTotal(resistances);
System.out.println("Total resistance is " + totalResistance);
}

public static Double addResistance(String endPoints, Double value, HashMap <String, Double> resistances){
if(resistances != null){

if(resistances.get(endPoints) == null){
resistances.put(endPoints, value);
}else{
Double temp = resistances.get(endPoints);
resistances.put(endPoints, 1/value + 1/temp);
}
}else{
resistances.put(endPoints, value);
}
return resistances.get(endPoints);
}

public static Double computeTotal(HashMap <String, Double> resistances){
Collection <Double> values = resistances.values();
Double sum = 0.0;
for(Iterator <Double> it = values.iterator();it.hasNext();){
sum = sum + it.next();
}
return sum;
}

}``````

Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

### Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

### Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.