Amazon Interview Question for Quality Assurance Engineers






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

we have the top left & bottom right coordinated of the sqaures..
find :

int x1 = max(topleft_first_sq_x,topleft_sec_sq_x);
int y1 = max(topleft_first_sq_y,topleft_sec_sq_y);

int x2 = min(bottomright_first_sq_x,bottomright_sec_sq_x);
int y2 = min(bottomright_first_sq_y,bottomright_sec_sq_y);

if (x2>x1 && y2>y1)
they intersect
else
they dont

- Anonymous June 20, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I doubt whether this works for all cases

Consider square 1 with topleft(1,3) and bottom right(3,1)
square 2 with topleft(2,4) and bottom right(4,2)

both these squares intersect at 2 points

by your algorithm
x1=max(1,2)=2
y1=max(3,4)=4

x2=min(3,4)=3
y2=min(1,2)=1

x2>x1 is true
but y2>y1 is false
but still they intersect

- Anonymous June 27, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

We Need to Check Only Boundary Conditions That will make sure whether two polygon intersects or not ..i don't found any issue with such approach :)

- WgpShashank June 20, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

the answer is not the obvious one, comparing the x and y values of the sides...
he mentioned it already.

- sridhar June 25, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Its pretty simple actually - just try to verify that they do NOT intersect:
- Let the boxes (rectangles) be represented by two points each. Let the points be (a,b) and (c,d) for first and (w,x) and(y,z) for the second.
- Check for all four cases where the cannot intersect:
> One box is to the left of other - its a & c will be less than w and x of the other
> One box is to the right of the other, its a & c will be greater than w and x of the other
> One box is vertically higher than other
> or the first box is vertically lower than the other

//Here is code:

bool DoIntersect(Rectangle rectFirst, Rectangle rectSecond)
{
int a = rectFirst.bottomLeft.X;
int b = rectFirst.bottomLeft.Y;
int c = rectFirst.topRight.X;
int d = rectFirst.topRight.Y;

int w = rectSecond.bottomLeft.X;
int x = rectSecond.bottomLeft.Y;
int y = rectSecond.topRight.X;
int z = rectSecond.topRight.Y;

// checking for x co-ordinates
if(a<w && c<w && a<y && c<y) return false;
if(a>w && c>w && a>y && c>y) return false;

// checking for y co-ordinates
if(b<x && d<x && b<z && d<z) return false;
if(b>x && d>x && b>z && d>z) return false;

return true;
}

- Anonymous July 18, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

What about concentric squares of different sizes, they do not intersect, yet they would return true.
(0,0),(3,3) and
(1,1),(2,2)

- Sean December 08, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Think in opposite direction:
Think for the condition when two squares can't overlap, and the question becomes simple.

- -- March 14, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Take the area of the squares and the screen.

If Area(Screen) - Area(Square1) = Area(Square2), then there is no intersection.

Else, there is an intersection.

Think of it this way. Imagine two squares that do not intersect. Then if you subtract the area of the screen from the area of the square you should get the area of square 2.

If they intersect, subtracting one of the squares from the area of the screen will result in a value less than the other square since a portion of the square would have been taken out.

This took me a while to solve haha.

- Ethan December 20, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I lied. This doesn't work haha.

- Anonymous December 20, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Two squares, if they intersect, at least one of the point of one square is inside the other.
Do following steps:
1. take two adjacent points (A and B) of a square (S1), calculate the vector which perpendicular to the edge and point out, say v1.
2. take one point (P) from the other square (S2), calculate the vector of PA and PB, say v2
3. calculate the dot product of v1 and v2.
4. repeat 1-3 (for all adjacent points of S1, if the point is inside the square, then all the dot products will be positive or 0.

- Anonymous May 18, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

geek for geek

# include<stdio.h>
# include<stdlib.h>
# define bool int

/* Function to find minimum of 3 numbers */
unsigned min(unsigned , unsigned , unsigned );

/* Function to get the nth ugly number*/
unsigned getNthUglyNo(unsigned n)
{
unsigned *ugly =
(unsigned *)(malloc (sizeof(unsigned)*n));
unsigned i2 = 0, i3 = 0, i5 = 0;
unsigned i;
unsigned next_multiple_of_2 = 2;
unsigned next_multiple_of_3 = 3;
unsigned next_multiple_of_5 = 5;
unsigned next_ugly_no = 1;
*(ugly+0) = 1;

for(i=1; i<n; i++)
{
next_ugly_no = min(next_multiple_of_2,
next_multiple_of_3,
next_multiple_of_5);
*(ugly+i) = next_ugly_no;
if(next_ugly_no == next_multiple_of_2)
{
i2 = i2+1;
next_multiple_of_2 = *(ugly+i2)*2;
}
if(next_ugly_no == next_multiple_of_3)
{
i3 = i3+1;
next_multiple_of_3 = *(ugly+i3)*3;
}
if(next_ugly_no == next_multiple_of_5)
{
i5 = i5+1;
next_multiple_of_5 = *(ugly+i5)*5;
}
} /*End of for loop (i=1; i<n; i++) */
return next_ugly_no;
}

/* Function to find minimum of 3 numbers */
unsigned min(unsigned a, unsigned b, unsigned c)
{
if(a <= b)
{
if(a <= c)
return a;
else
return c;
}
if(b <= c)
return b;
else
return c;
}

/* Driver program to test above functions */
int main()
{
unsigned no = getNthUglyNo(150);
printf("%dth ugly no. is %d ", 150, no);
getchar();
return 0;
}

- Anonymous November 20, 2013 | 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