X DAYS

:

HOUR

:

MINS

:

SEC

Copied to Clipboard
Check If two Line segments Intersect
Easy Accuracy: 30.58% Submissions: 1733 Points: 2

Given the coordinates of the endpoints(p1-q1 and p2-q2) of the two line-segments. Check if they intersect or not.

Example 1:

Input:
p1=(1,1)
q1=(10,1)
p2=(1,2)
q2=(10,2)
Output:
0
Explanation:
The two line segments formed
by p1-q1 and p2-q2 intersect.

Example 2:

Input:
p1=(10,0)
q1=(0,10)
p2=(0,0)
q2=(10,10)
Output:
1
Explanation:
The two line segments formed
by p1-q1 and p2-q2 intersect.

You don't need to read input or print anything. Your task is to complete the function doIntersect() which takes the four points as input parameters and returns 1 if the line segments intersect. Otherwise, it returns 0.

Expected Time Complexity:O(1)
Expected Auxillary Space:O(1)

Constraints:
-106<=X,Y(for all points)<=106

### Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

#### My Submissions:  