Amazon Interview Question for Software Engineer / Developers


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.

- eugene.yarovoi July 21, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

you have to just find the total_resistance...

- cobra July 21, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

my be interviewer want b/t A to D

- niraj.nijju July 21, 2012 | Flag
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
AD = 10 ohm
how will you solve it theoretically ??

- cobra July 21, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

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

create an adjacency matrix.
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..

- cobra July 21, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

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

- nachi July 21, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@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"...

- cobra July 21, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

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

- axecapone July 21, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@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.

- Anonymous July 22, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

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

- eugene.yarovoi July 22, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@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.

- Anonymous July 23, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Do we have to take care of The Bridge Circuit?

- nerd July 22, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

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.

- Piyush July 26, 2012 | Flag
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.
then juz addition of linklist will be our ans.

- Yadhuvanshi2504 July 22, 2012 | Flag Reply
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

- krbchd July 24, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Can you elaborate more on your hash approach

- begineer July 24, 2012 | Flag
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;
	}	


}

- SonicX July 30, 2012 | Flag Reply


Add a Comment
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.

Learn More

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.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More