Yahoo Interview Question for Software Engineer / Developers






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

connected component analysis.

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

I would traverse every line keeping track of the ranges of black points. For example, if I have on a line: WWWBBWWWBBBWW, then I have the ranges [3-4] and [8-10].
For every range found, I would look for the ranges from the previous line that share some of the columns, then I would connect both ranges, one on another. For example WWBBWWWWWWWWB, has the ranges [2-3] and [12-12] and the first range share some columns with the first range of the previous example. When looking for share, we would have to consider dialgonals (its just a matter of expanding the ranges of the previous line by a unit of 1 on each limit).
After the last line I would have ranges connected to one another. Now the problem is to find how many graphs I have, which I can do flagging the nodes in a DFS, starting at every range that is not flagged already.
The answer is the number of graphs.

- JPFerreira April 07, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Copy the array if possible, (or modify it in place) - or, subvert one of the RGB components perhaps for our own purpose - traverse along, till you see a black pixel; bump the count of these blobs. Do a flood fill of black to white from that point (see wikipedia; the code is simple) and keep going.

- Jeff Donner October 06, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Think this can be achieved using the flood fill algorithm.
Represent this picture as a bitmap i.e. a 2D array. Each element in the array is a number which represents a color. For now it only takes black and white.
1. Start traversing the array from 0,0.
2. Once you find a black color pixel stop.
3. Start to flood fill with target color as black and replacement color as something else say red.
4. Once done increment your count and start searching the matrix from where we stopped and repeat the above step 2.

This time the previous shape won't be considered since it is colored red now.

- someone February 02, 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