  Showing: Handle Score
@Ibrahim Nash 6560
@mb1973 5777
@Quandray 5271
@akhayrutdinov 5111
@saiujwal13083 5074
@kirtidee18 4356
@sanjay05 3762
@mantu_singh 3638
@gfgaccount 3601
@marius_valentin_dragoi 3525
Max value after m range operation
Basic Accuracy: 71.69% Submissions: 438 Points: 1

Given an array arr of size N with all initial values as 0, the task is to perform the following M range increment operations as shown below:
Increment(ai, bi, ki) : Increment values from index 'ai' to 'bi' by 'ki'.
After M operations, calculate the maximum value in the array arr[].

Example 1:

Input: N = 5, M = 3, a[] = {0, 1, 2}
b[] = {1, 4, 3}, k[] = {100, 100, 100}
Output: 200
Explanation: Initially array = {0, 0, 0,
0, 0}
After first operation : {100, 100, 0, 0, 0}
After second operation: {100, 200, 100, 100, 100}
After third operation: {100, 200, 200, 200, 100}
Maximum element after m operations is 200.

Example 2:

Input: N = 4, M = 3, a[] = {1, 0, 3}
b[] = {2, 0, 3}, k[] = {603, 286, 882}
Output: 882
Explanation: Initially array = {0, 0, 0, 0}
After first operation: {0, 603, 603, 0}
After second operation: {286, 603, 603, 0}
After third operation: {286, 603, 603, 882}
Maximum element after m operations is 882.

You don't need to read input or print anything. You just need to complete the function findMax() that takes arrays a[], b[], k[] and integers N, M as parameters and returns the desired output.

Expected Time Complexity: O(M+N).
Expected Auxiliary Space: O(N).

Constraints:
1 ≤ N ≤ 106

0 ≤ ai ≤ bi ≤ N-1
1 ≤ M ≤ 106
0 ≤ ki ≤ 106

### Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

#### My Submissions:  