Google Interview Question for Java Developers


Country: United States




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

fix any arbitary point, find another point that results in the minimum/maximum slope

- Mehdi January 16, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Graham scan algorithm.

- Computational geometry January 15, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Graham scan could be used to find convex hull.

- Computational geometry January 15, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Create equation of the line by selected two points.
Check every other point by this equation:
if result >0 then point at one side of the line
if result < 0 then point at another side of the line
if result == 0 the point belongs to line.

- Alex.Velichko January 16, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Absolutely right Computational Geometry, Thats Convex Hull. Crazy Question man

- hprem991 January 16, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static Point[] func(Point[] points) {
        if (points == null || points.length <= 1) return null;
        Point[] answer = new Point[2];
        int length = points.length;
        Point firstPoint = points[0];
        int j = 0;
        for (int i = 1; i < length; i++) {
            Point tempPoint = points[i];
            if (tempPoint.x < firstPoint.x) {
                firstPoint = tempPoint;
                j = i;
            }
        }
        answer[0] = firstPoint;
        answer[1] = points[(j+1)%length];
        for (int i = 0; i < length; i++) {
            boolean flag = checkDirection(answer[0], points[i], answer[1]);
            if (flag) {
                answer[1] = points[i];
            }
        }
        return answer;
}

private static boolean checkDirection(Point p1, Point p2, Point p3) {
        int value = ((p3.y - p2.y)*(p2.x-p1.x)) - ((p2.y - p1.y)*(p3.x-p2.x));
        if (value > 0) return true;
        return false;
}

static class Point {
        int x;
        int y;
        Point (int xx, int yy) {
            x = xx;
            y = yy;
        }
}

- Aim_Google January 17, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Only the first step of a graham scan is needed. Scan once for the lowest x co-ordinate and find another point with the largest angle to that point.

- jayz January 20, 2018 | 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