Interview Question for Software Engineer in Tests


Country: England
Interview Type: Phone Interview




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

1. I would compute the area of the triangle..
2. and then create 3 triangles following the rule:
- take two points off the old triangle and
- put it with the new point and then
-compute the area.
3. check if the sum of the 3 new triangles =old sum

- dorohanter April 17, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

By using slopes, we can tell whether given point is inside triangle or not .

1. Let us assume A,B,C are triangle points. P is given point to check whether it is inside traingle or not.

2. calculate Slopes AB,AC,AP . AP slope should be between AB and AC.
3. similarly calculate BA,BC,BP slopes. BP slppe should be between BA and BC .
4. similarly calculate CA,CB,CP slopes. CP slppe should be between CA and CB .

if 2,3,4 statements true, then we can say Point P is inside traingle .

- siva.sai.2020 April 18, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Find the 3 equations of the lines and check if the point is on the appropriate side of the lines.

- VadimM April 17, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

then its either an angle or a straight line

- andy April 17, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

then its either an angle or a straight line

- andy April 17, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

then its either an angle or a straight line

- andy April 17, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

then its either an angle or a straight line

- andy April 17, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

We can think for generic polygon solution where take all the points in the side of the triangle, now see on the Y axis, how many points are there with the Point (to find) Y; if it is odd number of points then the point is inside the triangle, if there are even number of points then it not inside the triangle.

- howaboutthis April 18, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I cannot understand your solution. could you please elaborate your answer ?

- siva.sai.2020 April 18, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

First rotate the trangle & given point such that one of the edge of the trangle should lie on X-axis.
Now compare the given point X-co-ordinate if it is +ve (or) ZERO(point lies on the trangle) increase count value.
Repeat the same for remaining two edges.
If count value is 3 then it lies inside if not it is out side.

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

Find minX, minY, maxX, maxY.
if minX is smaller than xToFind and maxX larger than xToFind and minY smaller than yToFind and maxY larger than yToFind the point (xToFind,yToFind) is inside the triangle

- Max April 22, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I guess this is not good enough.
The point can lie within the rectangle formed by (Xmax, Xmin, Ymax,Ymin) and still outside the triangle mentioned here.

- Debdeep April 25, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Find equations of all the three lines (using slope and intercept concept).
Then for each equation, if the 3rd point of triangle and given point are on same side, the given point in inside the triangle.

To check whether two points are on same side of the triangle, substitute x and y values of both points in the equation and if the result is same sign (positive or negative), they are on the same side of the line.

- Anshu May 27, 2012 | 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