## Shutterfly Interview Question for Software Engineer / Developers

Country: United States

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

start searching from top right corner(i.e, 1row last element) of square.
1. if element is lessa than current element go left
else go down(i.e next row same coloumn)

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

Started from the top-right corner after clarifying that the matrix will be a 2-d matrix and walked either left or down. I unfortunately screwed up on the big-O analysis.

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

What is a sorted matrix? is the last element of a row smaller than the first element of the next row? or each row is independently sorted?

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

Here is an algo that works pretty well, though it is weird why you would ever want to do this. Probably more appropriately would be to hold this in a flat array and do a binary search on it, but I guess you can do sort of a multi-dimensional binary search. This should perform in O(log N) time.

``````static bool search(int [,] ints, int data)
{
int mid_1 = ints.Length / SIZE / 2;
int mid_2 = mid_1;

while (mid_1 >= 0 && mid_1 < ints.Length / SIZE)
{
if (ints[mid_1, mid_2] == data)
return true;

if (ints[mid_1, mid_2] > data)
{
for (int x = mid_2 - 1; x >= 0; x--)
{
if (ints[mid_1, x] == data)
return true;
}
mid_1--;
}
else
{
for (int x = mid_2 + 1; x < ints.Length / SIZE; x++)
{
if (ints[mid_1, x] == data)
return true;
}
mid_1++;
}
}
return false;
}``````

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

There are no algos that can successfully solve this problem in O(logN) time. O(N) is the best you can do.

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.