Car Pooling Capacity Problem
You are a cab driver with a car that initially has 'C' empty seats. The car moves in a straight line towards the forward direction only. Your job is to determine if it is possible to complete all passenger trips provided.
You must check the feasibility of handling all 'N' given trips where each trip specifies the number of passengers, their pickup point, and their drop-off point.
The challenge is to determine if it is feasible to accommodate all trips without exceeding the car's capacity at any point in time.
Input:
The first line contains a single integer ‘T’, denoting the number of test cases.
Each test case contains:
- First line: two integers 'C' (car capacity) and 'N' (number of trips).
- Next 'N' lines: each containing three integers 'Num', 'pickPoint', and 'dropPoint' representing the number of passengers, pickup point, and drop-off point for each trip.
Output:
For each test case, output “True” if it is possible to handle all trips within the car capacity, otherwise output “False”.
Example:
Input:
1
4 3
2 1 5
3 3 7
1 5 7
Output:
False
Explanation:
At pickup point 3, you pick up 3 more passengers, totalling to 5, which exceeds the car capacity of 4.
Constraints:
1 <= T <= 50
1 <= C <= 10^5
1 <= N <= 10^3
0 <= passengers <= 100
0 <= pickPoint, dropPoint <= 1000
Note:
A special type of car can hold any number of seats.
You are required only to implement the function; input/output operations are already handled.
Top Fractal Analytics Software Engineer interview questions & answers
Popular interview questions of Software Engineer
Top HR questions asked in Fractal Analytics Software Engineer
Reviews
Interviews
Salaries
Users/Month