Given equations of two lines (a1, b1, c1) and (a2, b2, c2) such that (ai, bi, ci) are the coefficients of X2, X and a constant term of the straight line respectively, in the general equation , the task is to check if both the straight lines are parallel or not. If they are found to be parallel, then print “Yes”. Otherwise, print “No”.
Input: a1 = -2, b1 = 4, a2 = -6, b2 = 12
The slope of both lines are equal i.e., a1/b1 = a2/ b2 = -2.
Input: a1 = 11, b1 = 3, a2 = 7, b2 = -10
The slope of both lines are not equal i.e., a1/b1≠ a2/b2.
Approach: To check if two lines are parallel to each other or not, the idea is to compare the slope of the given lines. If the slope of the given lines is equal then the given lines are parallel. Therefore, print “Yes” else print “No”.
Below is the implementation of the above approach:
Time Complexity: O(1)
Auxiliary Space: O(1)
Attention reader! Don’t stop learning now. Get hold of all the important mathematical concepts for competitive programming with the Essential Maths for CP Course at a student-friendly price. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.