Check If two Line segments Intersect
Easy Accuracy: 30.95% Submissions: 1027 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.


Your Task:
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

We are replacing the old Disqus forum with the new Discussions section given below.
Click here to view old Disqus comments.


to report an issue on this page.

Editorial

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

Yes

All Submissions

My Submissions:

Login to access your submissions.

Check If two Line segments Intersect

Output Window