Interview Question


Country: United States




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

A greedy algorithm is optimal here. I suppose a good answer would include a proof that this is so.

- eugene.yarovoi December 05, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

can you clarify the following?

if page break is happening only once, then what do you mean by return all positions of pixels?

Do you mean breaking the matrix in to multiple pages such that all rows between two white rows are skipped?

Also, if its a Nx1000 matrix isn't it mean N rows and 1000 columns or do you mean to say NxN matrix with N is atmost 1000?

Regards

- Somisetty November 29, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Sorry I forgot to mention.
Page size is 1000 X 1000, so you have to break the N X 1000 matrix according to the mentioned conditions in 1000 X 1000 matrices.
The program should return the number of pages used to print and the position of pixels on the matrix where the page breaks were applied.

- javacode7 November 29, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Can someone help me with this question?

- javacode7 November 29, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

using javascript...

function getPageBreaks(img, N) {
    var i=0, prevAllWhite=0, pageLineCount=0, pageBreak=0, breaksStack = [];
    while (i < N) {
        // isAllWhiteLine just scans the line looking for a black pixel
        if (isAllWhiteLine(img, i)) {
            prevAllWhite = i;
        }

        if (++pageLineCount === 1000) {
            if (prevAllWhite > 0) {
            	pageBreak = prevAllWhite;
            } else {
            	pageBreak = pageBreak + pageLineCount;
            }
            breaksStack.push(pageBreak);

            prevAllWhite = 0;
            pageLineCount = 0;
        }
        ++i;
    }

    if (pageLineCount > 0) {
        breaksStack.push(pageBreak + pageLineCount);
    }

    // The number of pages is breaksStack.length
    return breaksStack;
}

- cat November 30, 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