SalesForce OA-9 2023
Problem Description
You are given three points: a(x1, y1), b(x2, y2), and c(x3, y3). The task is to check whether these points form a non-degenerate triangle. Additionally, you are provided two other points, p(x_p, y_p) and q(x_q, y_q). If the points form a valid triangle, you need to check whether p and q lie inside the triangle or not.
Input Format:
- The first line contains two integers:
x1
andy1
, the coordinates of point a. - The second line contains two integers:
x2
andy2
, the coordinates of point b. - The third line contains two integers:
x3
andy3
, the coordinates of point c. - The fourth line contains two integers:
xp
andyp
, the coordinates of point p. - The fifth line contains two integers:
xq
andyq
, the coordinates of point q.
Output Format:
- Print the following based on the conditions:
0
if the points a, b, and c do not form a valid triangle (i.e., they are collinear).1
if p is inside the triangle and q is not.2
if q is inside the triangle and p is not.3
if both p and q are inside or on the triangle.4
if neither p nor q are inside or on the triangle.
Constraints:
- ( 0 <= x1, y1, x2, y2, x3, y3, x_p, y_p, x_q, y_q <= 10^5 )
Example 1:
Input:
0 0
100 0
0 200
12 21
21 21
Output:
3
Example 2:
Input:
0 0
1 1
2 2
12 21
21 21
Output:
0