FastPrepTriangle and Points
Problems/Triangle and Points

Triangle and Points

GreyOrange logoGreyOrange● EasyOA

Updated Sep 2026

QuestionFunctionExamples

Problem statement

You are given the coordinates of a triangle with three vertices:

  • (x1, y1)
  • (x2, y2)
  • (x3, y3)

You are also given two points:

  • Point p = (xp, yp)
  • Point q = (xq, yq)

Return the following code:

  1. Return 1 if the three vertices cannot form a triangle.
  2. Return 2 if both p and q lie inside the triangle.
  3. Return 3 if only p lies inside the triangle.
  4. Return 4 if only q lies inside the triangle.
  5. Return 5 if neither point lies inside the triangle.

Boundary rule: A point on an edge or exactly on a vertex is considered inside the triangle.

Input: The triangle coordinates x1, y1, x2, y2, x3, y3, followed by the point coordinates xp, yp, xq, yq.

Function

triangleAndPoints(x1: int, y1: int, x2: int, y2: int, x3: int, y3: int, xp: int, yp: int, xq: int, yq: int) → int

Examples

Example 1

x1 = 0y1 = 0x2 = 5y2 = 0x3 = 0y3 = 5xp = 1yp = 1xq = 6yq = 6return = 3

Only point p lies inside the triangle.

More GreyOrange interview questions

  • Array OperationsOA · Seen Oct 2024
  • Roman Numerals in StringsOA · Seen Oct 2024

Similar questions at other companies

  • Overlapping Random Time WindowsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
  • Squared Frobenius Norm of a Reflect-and-Stretch MapWalleye Capital · OA
  • Circles RelationshipIBM · OAIBM interview questions
  • Slope of a Nonvertical LineMorgan Stanley · OAMorgan Stanley interview questions
  • Cyber Beacon DetectionRippling · OARippling interview questions
  • Do They Belong?Goldman Sachs · OAGoldman Sachs interview questions
  • Closest Point to a LineAdobe · OAAdobe interview questions
  • Range of a Third CorrelationTower Research Capital · PHONE SCREEN
  • Three Points in a Semicircle: Monte Carlo EstimateSquarepoint Capital · PHONE SCREENSquarepoint Capital interview questions
  • Union Area of Two RectanglesDocuSign · PHONE SCREENDocuSign interview questions
See GreyOrange hiring insights
Saved
class Solution {
    public int triangleAndPoints(int x1, int y1, int x2, int y2, int x3, int y3, int xp, int yp, int xq, int yq) {
      // write your code here
    }

}
Checking account…