FastPrepPoint Inside a Triangle

Point Inside a Triangle

SambaNova Systems logoSambaNova Systems● MediumFULLTIMENEW GRADPHONE SCREENONSITE INTERVIEW
Learn

Problem statement

Given three non-collinear integer triangle vertices and one integer point, return whether the point lies inside the triangle.

A point on an edge or vertex counts as inside. The vertices may be clockwise or counterclockwise.

Function

isPointInsideTriangle(triangle: int[][], point: int[]) → boolean

Examples

Example 1

triangle = [[0,0],[5,0],[0,5]]point = [1,1]return = true

The point lies strictly inside.

Example 2

triangle = [[0,0],[5,0],[0,5]]point = [3,3]return = false

The point lies beyond the hypotenuse.

Example 3

triangle = [[0,0],[5,0],[0,5]]point = [0,2]return = true

An edge point counts as inside.

Constraints

  • triangle.length == 3, every coordinate row has length 2, and point.length == 2.
  • Coordinates are between -10^9 and 10^9.
  • The triangle has nonzero area.

More SambaNova Systems problems

See SambaNova Systems hiring insights
public boolean isPointInsideTriangle(int[][] triangle, int[] point) {
    // write your code here
}
triangle[[0,0],[5,0],[0,5]]
point[1,1]
expectedtrue
Checking account…