## Shutterfly Interview Question

Software Engineer / Developers**Country:**United States

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;
}
```

start searching from top right corner(i.e, 1row last element) of square.

- devendar August 09, 20121. if element is lessa than current element go left

else go down(i.e next row same coloumn)