InterviewBit Academy is now Scaler!
InterviewBit Academy is now Scaler Academy!

Intersection of Two Lines

Problem Description

Given two lines a1x + b1y + c1 = 0 and a2x + b2y + c2 = 0, find the intersection point of the two given lines.

NOTE:

  • If these lines don't intersect, return [-1, -1].
  • If lines intersects, point of intersection will have integer coordinates.



Problem Constraints

-109 <= a1, b1, c1 <= 109
-109 <= a2, b2, c2 <= 109



Input Format

First argument is an integer array A of size 3 where A[0] = a1, A[1] = b1 and A[2] = c1.
Second argument is an integer array B of size 3 where B[0] = a2, B[1] = b2 and B[2] = c2.



Output Format

Return an integer array C of size 2. C[0] = X and C[1] = Y where (X, Y) is the point of intersection.



Example Input

Input 1:

 A = [1, -1, 0]
 B = [1, 1, 0]

Input 2:

 A = [1, -1, 1]
 B = [0, 1, -2]



Example Output

Output 1:

 [0, 0]

Output 2:

 [1, 2]



Example Explanation

Explanation 1:

 Given two lines intersects at the origin i.e. (0, 0).

Explanation 2:

 Given two lines are: x - y + 1 = 0 and y - 2 = 0.
 Put y = 2 in the first line equation. We get x = 1. So, the point of intersection is (1, 2).



NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Intersection of Two Lines on Interview Code Editor
Sign Up
to access hints and editorial solutions for Intersection of Two Lines

Discussion


Loading...
Click here to start solving coding interview questions