Amazon Interview Question for Software Engineer / Developers






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

Here is my take:
A simple crossroad can have traffic moving in 8 possible combinations:
1. Curve paths: East->North, North->West, West->South and South->East (first is the inital direction of motion and second is the direction after making a curve).
2. Straight path: All four directions.

Out of this two can happen at the same time:
ex: North->West and South->East and also in heading east and heading west can flow at the same time.

Thus out of eight combinations we have to decide only among 4 combinations, this is similar to a 2 bit problem where the state can revolve around four possible states:
00
01
10
11

Yes, more complex things can be incorporated as changing the interval to avoid congession etc. But this can give a head start to solve bigger problems :)..

- Anonymous March 13, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

We can have a Signal class, which is inherited by vehicle Signal and Pedestrian Signal.
Signal{
LED
Timer
}

Class SignalManager{
VehicleSingnal[4];
PedestrianSingnal[8];

doWork()
{
while ( true)
switch on the signals in roundrobin fashion
}

}

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

No NO NO And NOOOO... you can not. There are complex parameters here, example Poisssion dist...which needs to be taken care of to stop clogging traffic, also need to have a feedback mechanism. Just not easy to design it.

- becga March 11, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

All the 4 bit integer values where the number of 1s need to be 2 only.

- naveen.dixit May 19, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

A cross road would have 4 roads at the intersection viz North (00), South (11), East (10) and West (01). These roads can be represented in binary format as represented in brackets.
The 4 major conditions to be active simultaneously are

1. NS and SN
2. EW and WE
3. NW and SE
4. ES and WN

if we consider the binary representation of the above conditions then
we get
1. 0011 and 1100
2. 1001 and 0110
3. 0001 and 1110
4. 1011 and 0100

Thus at any point of time the negation of the binary representation would be active at that time simultaneously

- ketz January 04, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Please refer to :
ccs.neu.edu/home/vkp/Papers/Traffic-sigcse98.pdf

The solution given here can be extended to multiple lanes. Here are the basic classes :

Road
Place
Vehicle
TrafficSignal

If there is necessity for implementing pedestrian crossing, then we need two more classes: PedestrianSignal and Pedestrian

A road will have a set of places. Each place will have the link to next place in the valid direction. The place will maintain a queue of vehicles. Vehicles can be identified by their licence plate and make. Traffic signal will have three states, Red, Yellow and Green. The state transition will be based on a timer. There needs to be 4 signal objects to represent a 4 way intersection. Whenever the signal goes green, the cars can be dequeued from the place in the direction of the signal one at a time. When the state changes to red, the dequeue operation has to be stopped. A vehicle has to queue itself in the Place in direction where it wants to travel.

- PJ June 01, 2013 | 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