Ninja and Geometry Problem Statement

In this problem, Ninja is provided with two lines on a 2D plane. The first line 'AB' is determined by two points A and B. The second line 'PQ' is determined by two points P and Q. The task is to calculate the intersection point of these two lines with precision up to six decimal places. If the lines do not intersect, the output should be -1.000000 -1.000000.

Input:

The first line provides an integer ‘T’ representing the number of test cases. Each test case consists of one line containing eight space-separated integers: 
‘AX1’, ‘AY1’, ‘BX2’, ‘BY2’, ‘PX1’, ‘PY1’, ‘QX2’, ‘QY2’

Output:

For each test case, output the intersection point’s coordinates (X, Y) with a precision of six decimal places on a new line. If there is no intersection, return -1.000000 -1.000000.

Example:

Input:
2
0 3 3 0 0 0 5 5
1 1 2 2 3 3 4 4
Output:
1.500000 1.500000
-1.000000 -1.000000
Explanation:

For the first test case, the lines intersect at (1.500000, 1.500000). For the second test case, the lines do not intersect, hence the output is -1.000000 -1.000000.

Constraints:

  • 1 <= ‘T’ <= 102
  • 1 <= ‘AX1’, ‘AY1’, ‘BX2’, ‘BY2’, ‘PX1’, ‘PY1’, ‘QX2’, ‘QY2’ <= 105
  • The lines ‘AB’ and ‘PQ’ are distinct.

Note:

You do not need to format the output to six decimal places manually; it’s handled in the function implementation. The problem may involve precision handling due to floating-point arithmetic.

AnswerBot
4mo

Calculate the intersection point of two lines on a 2D plane with precision up to six decimal places.

  • Parse input integers for each test case

  • Implement line intersection algorithm

  • Handle precision up to s...read more

Help your peers!
Select
Add answer anonymously...

Atlassian Software Developer Intern interview questions & answers

A Software Developer Intern was asked Q. Design an API service to limit the number of accesses for a user to a function w...read more
A Software Developer Intern was asked 12mo agoQ. Longest increasing subsequence
A Software Developer Intern was asked Q. Ninja and Geometry Problem Statement In this problem, Ninja is provided with two...read more

Popular interview questions of Software Developer Intern

A Software Developer Intern was asked Q1. Design an API service to limit the number of accesses for a user to a function w...read more
A Software Developer Intern was asked 12mo agoQ2. Longest increasing subsequence
A Software Developer Intern was asked Q3. Ninja and Geometry Problem Statement In this problem, Ninja is provided with two...read more
Atlassian Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits