We are given two lines a1x + b1x + c1 and a2x + b2y + c2, we need to find the intersection points of the lines.
Now, given two lines a1x + b1x + c1 and a2x + b2y + c2, we can find the intersection of the lines by the formula:-
x’ = (b1c2 - b2c1)/(a1b2 - a2b1)
y’ = (c1a2 - a1c2)/(a1b2 - a2b1)
You just need to take care of the point that in Java infinity is printed as ‘Infinity’ and in other languages it’s printed different, e.g. ‘inf’ in C++. You need to print ‘Infinity’ to get AC.
You can find the author’s solution and my solution below. Hope this helps.