Car Pooling

You are working as a cab driver. Your car moves in a straight line and moves toward the forward direction only. Initially, you have ‘C’ empty seats for the passengers.

Now, you are given ‘N’ number of trips that you have to make. In each trip, you are given three integers ‘Num’, ‘pickPoint’, and ‘dropPoint’ denoting that there are ‘Num’ numbers of passengers standing at 'pickpoint’ and you have to drop them at 'droppoint’.

Your task is to find if it is possible to pick up and drop off all the passengers of all the given trips or not.

Note :
You have a special type of car containing any number of seats.
Input Format :
The first line contains a single integer ‘T’, denoting the number of test cases.

Each test case’s first line contains ‘C’ and ‘N’, denoting the car’s capacity and the number of trips you have to make.

The next ‘N’ lines contain 3 integers, each denoting the number of passengers, pick up point, and drop point of the trip respectively.
Output Format :
For each test case, print “True” if possible to make the trip and “False” otherwise.

Print the output of each test case in a separated line.
Note :
You don’t need to print anything; It has already been taken care of. Just implement the given function.
Constraints :
1 <= T <= 50
1 <= C <= 10^5
1 <= N <= 10^3
0 <= passengers <= 100
0 <= pickPoint, dropPoint <= 1000

Where ‘T’ is the number of test cases, ‘C’ is the car’s capacity, and “N’ is the number of trips you have to make.

Time limit: 1 sec.
Be the first one to answer
Add answer anonymously...
Fractal Analytics Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
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

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

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter