Car Pooling Problem Statement

You are tasked with driving a cab that moves in a straight line, only forward, and initially has 'C' empty seats available for passengers.

Given 'N' trips, each defined by three integers: 'Num', 'pickPoint', and 'dropPoint'. These represent 'Num' passengers waiting at 'pickPoint' who must be dropped at 'dropPoint'.

Determine whether you can successfully pick up and drop off all passengers for each trip.

Input:

The first line includes an integer ‘T’, representing the number of test cases.

For each test case:
The first line contains two integers, ‘C’ and ‘N’, the car’s capacity and the number of trips, respectively.
The following 'N' lines each contain three integers denoting the number of passengers, the pickup point, and the drop-off point.

Output:

For every test case, output “True” if the trips can be made successfully and “False” otherwise.
Output results for each test case on a new line.

Example:

Input:
T = 2
C, N = 4 3
Trip 1: 2 1 5
Trip 2: 3 3 7
Trip 3: 1 5 9

C, N = 4 2
Trip 1: 2 1 5
Trip 2: 3 2 4

Output:
False
True

Constraints:

  • 1 <= T <= 50
  • 1 <= C <= 10^5
  • 1 <= N <= 10^3
  • 0 <= passengers <= 100
  • 0 <= pickPoint, dropPoint <= 1000

Note: You do not need to print anything; simply implement the function and return the appropriate responses.

AnswerBot
4mo

The problem involves determining if a cab with a certain capacity can successfully pick up and drop off passengers at specified points for multiple trips.

  • Create a function that takes in the car's capa...read more

Help your peers!
Select
Add answer anonymously...

Top Software Developer Interview Questions Asked at Amazon

Q. What is OOPS?
Q. What is Java programming?
Q. Could you describe the process for designing a data structure that allows for al...read more
Software Developer 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