Google Interview Question for Software Engineer / Developers


Country: United States
Interview Type: In-Person




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

It looks like the question is directly copy pasted from Stackoverflow: h t tp:// stackoverflow. com/questions/14994179/given-a-circle-with-n-defined-points-and-a-point-m-outside-the-circle-find-the

- Andrei February 12, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

How the defined points stored? Are they clockwise or randomly stored? If it is randomly, I guess it's impossible to do this in O(logn) time. If it is clockwise of anticlockwise, this is a binary search problem.

- Anonymous February 11, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
2
of 6 votes

Wow, seriously? If you still don't know how to measure distance between 2 points on a 2d-plane field, I highly doubt you made it to the face-to-face portion of google interviews. Stop copy-pasting glassdoor interview questions.

- Anonymous February 11, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

What about this:
(1)Get the line defined by the circle center O and the outside point P, then we can get the diameter AOB on this line. Let's say the endpoint close to P is A, and the other is B.
(2)Now all the N given points are in the circle defined by center P and radius PB, while no point is in the circle defined by center P and radius PA.
(3)Binary search radius till we find a radius R with which the defined circle has only one given point.

- uuuouou February 11, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 2 vote

Join the line from center of circle to the outside point. Now the point at minimum distance from M has the least angle with this line i.e. min(theta, 360 - theta) should be the least among all the points.
If we assume points are in order clockwise/anti clockwise this breaks down to the problem of rotated array which is solvable in log(N)

- kr.neerav February 11, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Hi, can you give more info on problem of rotated array? can you send me the link to this problem?

- jigili August 23, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Here's a verbal description of a logarithmic algorithm:

Let C be the center of the circle and let P be the point of intersection of the circle with the line segment joining C and M. Let N_i designate the ith point in the list of N points ordered counter-clockwise (we must assume they are given to us in an ordering like this), and let -pi <= A_i < pi be the the *signed* measure of the angle from P to N_i. Then the problem is reduced to finding the index i so that |A_i| is minimized.

Note that the list [ |A_1|, |A_2|, ..., |A_N| ] is cyclically sorted, i.e., it is either ascending and then descending or else it is descending and then ascending. We want to find the minimum element. This can be achieved in logarithmic time via a modification of binary search.

- nilkn February 12, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Assuming the points are in order

public static Point findClosest(final Point m, final List<Point> circlePoints)
    {
        int index = Collections.binarySearch(circlePoints, m, new Comparator<Point>() {
            @Override
            public int compare(Point o1, Point o2)
            {  
                int idx = circlePoints.indexOf(o1);
                double dist,distLeft, distRight;
                    dist = findDistance(o2, o1);
                if(idx-1>0)
                {
                    distLeft = findDistance(o2, circlePoints.get(idx-1));
                    if(distLeft<dist)
                        return 1;
                }
                if(idx+1<circlePoints.size())
                {
                    distRight = findDistance(o2, circlePoints.get(idx+1));
                    if(distRight<dist)
                        return -1;
                }
                return 0;
            }
            
        });
       return circlePoints.get(index);
    }


    public static Double findDistance(Point p1, Point p2)
    {
        if(p1==null || p2==null)
            return 0d;
        return Math.sqrt(Math.pow(p1.x-p2.x, 2)+Math.pow(p1.y-p2.y, 2)); 
    }



static class Point
    {
        Float x;
        Float y;
        public Point(float x, float y)
        {
            this.x = x;
            this.y = y;
        }
}

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

Idea: binary search for the smallest value
Use distance directly.
Compute three values for the middle point:
(1) if go down, choose the right half
(2) if go up, choose the left half
(3) if valley, return the answer

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

the question that makes sense to me is that setup is given with a circle and N points.
Then multiple queries are made with different points outside the above circle. Each query should return closet point from N point set.

- aditya.eagle059 February 10, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
-2
of 2 vote

I guess, we can modify the closest pair of points algorithm of complexity O(n logn) to run in (log n).

- Anonymous February 11, 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