
The first line contains an integer ‘T’ denoting the number of test cases. Then each test case follows.
The first input line of each test case contains two space-separated integers ‘N’ and ‘M’ denoting the number of flights and booking details, respectively.
Each of the next ‘M’ lines contains three space-separated integers [first, last, seats] denoting the booking details.
For each test case, print the ‘N’ space-separated integers denoting the elements of the “ANSWER” array/list.
Print the output of each test case in a separate line.
You are not required to print the expected output; it has already been taken care of. Just implement the function.
1 <= T <= 50
1 <= N, M <= 10^4
1 <= first, last <= N
1 <= seats <= 10^3
Where ‘T’ is the number of test cases, ‘N’ is the number of flights, ‘M’ is the length of booking details array/list and the three integers [first, last, seats] denote the details of a booking.
Time Limit: 1 sec
Approach: The basic idea for this approach is to traverse through each booking detail and then iterate through the range of flights for updating the count of reserved seats for each flight.
Consider the following steps:
Approach: The idea here is not to iterate through ‘START’ to ‘END’ for a booking detail. Instead, we can simply update the ‘ANSWER’ array/list as
Now, we can simply take the prefix sum over the 'ANSWER' array/list to get the answer.
Let us take test case 1 of sample testcase 1 as an example where booking = [ [1, 2, 3], [2, 3, 2], [1, 3, 1], [3, 4, 2] ]
Traverse the booking array/list and update the “answer” which is initially [0, 0, 0, 0]
Now, we will take the prefix sum.
Algorithm: