Find Slope Problem Statement
Given a linked list where each node represents coordinates on the Cartesian plane, your task is to determine the minimum and maximum slope between consecutive points.
Example:
Input:
P1(X1, Y1) -> P2(X2, Y2) -> P3(X3, Y3)
Output:
The starting node of the segment with maximum slope and the starting node of the segment with minimum slope.
Explanation:
Calculate slopes between consecutive points, i.e., Slope(P1, P2) and Slope(P2, P3). Identify and return the starting node of the segment with the maximum slope and the starting node of the segment with the minimum slope.
Constraints:
1 <= T <= 10
2 <= N <= 10^3
-10^9 <= X <= 10^9
-10^9 <= Y <= 10^9
Input:
The first line of input contains an integer 'T', the number of test cases. Each test case consists of linked list elements/nodes separated by spaces, terminated by -1. Each node consists of 'X' and 'Y' coordinates.
Output:
For each test case, return the nodes that start the segments with Maximum(Slope(P1, P2), Slope(P2, P3)) and Minimum(Slope(P1, P2), Slope(P2, P3)).
Note:
In case of multiple solutions, select the first occurring one. You don't need to print anything; implement the function as specified.
Be the first one to answer
Add answer anonymously...
Popular interview questions of Software Engineer Intern
>
HSBC Group Software Engineer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app