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)

- devendar August 09, 2012 | Flag Reply
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.

- edoc0code August 08, 2012 | Flag Reply
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?

- dc360 August 10, 2012 | Flag Reply
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;
        }

- Joe Coder August 08, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

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

Your analysis of your algorithm is completely incorrect. Your algorithm is O(N^2). Your algorithm itself is also incorrect (you never update mid2).

- Anonymous August 08, 2012 | Flag


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