Corporate Flight Bookings Problem Statement
You are given an array/list BOOKINGS
representing the booking details of 'N' flights from 1 to 'N'. Each booking detail consists of three positive integers: [first, last, seats]. This indicates a booking from flights 'first' through 'last' (inclusive) with 'seats' reserved for each flight within this range.
Your task is to return an array/list ANSWER
of length 'N', where ANSWER[i]
denotes the total number of seats reserved for the i-th flight.
Input:
The first line contains an integer ‘T’ representing the number of test cases. The first line of each test case contains two space-separated integers ‘N’ and ‘M’, indicating the number of flights and the number of booking details, respectively. Each of the next ‘M’ lines contains three space-separated integers: [first, last, seats], which represent the booking details.
Output:
For each test case, output ‘N’ space-separated integers denoting the elements of the ANSWER
array/list. Output each test case on a separate line.
Example:
Input:
2
5 3
1 2 10
2 3 20
2 5 25
3 2
1 1 10
2 2 20
Output:
10 55 45 25 25
10 20
Explanation:
For the first test case, the seat reservation for flights is as follows: flight 1 has 10 seats, flight 2 has 55 seats, flight 3 has 45 seats, etc.
Constraints:
1 <= T <= 50
1 <= N, M <= 104
1 <= first, last <= N
1 <= seats <= 103
Note: The expected output is not required to be printed; focus on implementing the function only.
Be the first one to answer
Add answer anonymously...
Popular interview questions of Software Developer Intern
>
Cisco Networking Academy Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
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