Vistaprint Interview Question for Software Engineer / Developers


Country: United States
Interview Type: In-Person




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

#include <iostream>
#define SIZE _whatever_number_you_like

struct paper{
string name;
int width;
int height;
} array[SIZE];

int numberOfSheets(int xx,int yy){
int surface = 0;
for(int i=0;i<SIZE;i++)
surface += array[i].width*array[i].height;
return (int)surface/xx*yy;
}

Time Complexity: O(SIZE)
Space Complexity: O(1)

- Anonymous October 24, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

This is an 2D bin packing problem.

Bin packing is known as a NP-hard problem. We can use heuristic/approximation algorithms to solve it: first fit, next fit, best fit,...

- ninhnnsoc October 24, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
2
of 2 votes

Well you have a fixed width and height for the paper, why would you try to guess fits? You just need to know how much surface you need to cover by making the total surface of the array of papers and then divide it by the surface occupied by one sheet of paper of width xx and height yy.

- Andrei Nicolae October 24, 2014 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

I guess you have already found the flaw by the above example.

- ninhnnsoc October 24, 2014 | Flag
Comment hidden because of low score. Click to expand.
-1
of 1 vote

#include <iostream> 
#define SIZE _whatever_number_you_like 

struct paper{ 
string name; 
int width; 
int height; 
} array[SIZE]; 

int numberOfSheets(int xx,int yy){ 
int surface = 0; 
for(int i=0;i<SIZE;i++) 
surface += array[i].width*array[i].height; 
return (int)surface/xx*yy; 
}

Time Complexity: O(SIZE)
Space Complexity: O(1)

(Sorry for the edit, I forgot to preserve the whitespace)

- Andrei Nicolae October 24, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
2
of 2 votes

You underestimate the answer.
Look at this example:
Products' size: 4x4, 5x1
Paper size: 4x6

- ninhnnsoc October 24, 2014 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

Now I understood what you mean and I will update my code. My mistake, sorry.

- Andrei Nicolae October 24, 2014 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

You give the lower bound on the number of sheets needed.

- ninhnnsoc October 24, 2014 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

Yes, I saw that right after I saw the example. I did not get the problem's hack right, I misunderstood its conclusion!

- Andrei Nicolae October 24, 2014 | 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