Apple Interview Question for Developer Program Engineers






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

we can divide the polygon into triangle.
consider a f(n)
if n==3,it is just a triangle,just return the area of S(n)
if (n>3),for each two edges adjacent ,we can create a triangle with it,
then we can get n/2 triangles and another polygon with n-(n/2)*2+n/2 edges.
then we can use recursion

- anonymous October 06, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I didn't really get your solution properly. Can you please explain it in code. Thanks !

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

is this method applicable to convex and non convex polygons both???

- pank.bh92 August 17, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

As a graphics guy with good computation geometry & rasterization knowledge I'm not clear on what the question wants; but here's how I would do the following (if I didn't have to use triangulation) :

*Run line-sweep algorithm on the polygon [ex: top -> bottom] (see wikipedia ) with an active edge list
*Stop at every intersection OR vertex and compute the area described by the sum of the area for the parallelogram generated by the cut from OldY to Y.

If you already have a triangulation; it seems like a pretty silly question since the problem devolves to computing the area of a set of triangles. And that's nothing less than the 0.5*determinant of the matrix populated with the row-vectors produced by taking any 2 pair of points for the triangle (think cross product)

- Chris T November 14, 2014 | 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