## Vistaprint Interview Question for Software Engineer / Developers

• 0

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)

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,...

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

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.

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.

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)

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

Look at this example:
Products' size: 4x4, 5x1
Paper size: 4x6

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.

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

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

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!

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.