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.
CodingNinjas
author
2y
Hash Map Implementation

The simple idea is that we will keep a record of the number of passengers changed at every time in a hash map ‘passengers’ where the key represents the time at which the number ...read more

CodingNinjas
author
2y
Efficient Approach

The range for staring and ending location varies from 0 to 1000 which is not a large range.

We will solve the problem as we did in the previous approach, but instead of using a hash ...read more

Help your peers!
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