Company: Greyorange

Difficulty: medium

Problem Statement

9. Do They Belong? Consider three points a(x1, y1), b(x2, y2) and c(x3, y3). They form a genuine, non-degenerate triangle only when the triangle inequality holds strictly for every pair of sides (where |ab| denotes the distance between a and b): |ab| + |bc| > |ac| |bc| + |ac| > |ab| |ab| + |ac| > |bc| Say a point is enclosed by the triangle if it sits either on its boundary or anywhere inside it. Given two further points p = (xp, yp) and q = (xq, yq), determine and return the applicable outcome number: 0: If a, b and c fail to form a valid non-degenerate triangle. 1: If point p is enclosed by the triangle but point q is not. 2: If point q is enclosed by the triangle but point p is not. 3: If both p and q are enclosed by the triangle. 4: If neither p nor q is enclosed by the triangle. Function Description Complete the function pointsBelong with the following parameter(s): int x1, y1, x2, y2, x3, y3 : integer coordinates of the three points that may create a valid triangle int xp, yp, xq

More Greyorange OA questionsInterview experiences