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
8d

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!
Add answer anonymously...
Amazon Software Developer 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

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