Amazon Interview Question for Software Engineer / Developers






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

Flood-fill (node, target-color, replacement-color):
1. If the color of node is not equal to target-color, return.
2. If the color of node is equal to replacement-color, return.
3. Set the color of node to replacement-color.
4. Perform Flood-fill (one step to the west of node, target-color, replacement-color).
Perform Flood-fill (one step to the east of node, target-color, replacement-color).
Perform Flood-fill (one step to the north of node, target-color, replacement-color).
Perform Flood-fill (one step to the south of node, target-color, replacement-color).
5. Return.

- pavan September 09, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Code :
public void flood(int x, int y){
if(obr[x][y] == 0 ){
obr[x][y] = 2;
flood(x+1,y);
flood(x,y+1);
flood(x-1,y);
flood(x,y-1);
}
}

- pavan September 09, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

You obviously missed the question. It explicitly says no recursion. If no recursion then even children can code this.

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

sorry i meant to say if recursion then even ...

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

en.wikipedia.org/wiki/Flood_fill

- Anonymous April 22, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Almost the same, but without recursion

Queue Q = {node n}

while(Q is not empty)
Node N = Q.deque()
If the color of node N is not equal to target-color,
continue
If the color of node is equal to replacement-color,
continue
Set the color of node to replacement-color.
Q.enque(one step to the east of node)
Q.enque(one step to the west of node)
Q.enque(one step to the north of node)
Q.enque(one step to the south of node)
Return.

- hmm February 05, 2011 | 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