Max Element After Update Operations
Given an array A
of size N
, initialized with all zeros, and another array ARR
of M
pairs of integers representing operations. Each operation consists of a range where each element within that range in A
is incremented by 1. The task is to find and return the maximum element in array A
once all operations have been performed.
Input:
n = 5
operations = [ (1, 5), (2, 4) ]
Output:
2
Example:
Suppose ‘N’ is 5. Initially, the array A
is [0, 0, 0, 0, 0].
Perform operation (1, 5), array becomes [1, 1, 1, 1, 1].
Next, perform operation (2, 4), array becomes [1, 2, 2, 2, 1].
The maximum element post operations is 2.
Constraints:
1 ≤ T ≤ 10
1 ≤ N ≤ 10^3
1 ≤ M ≤ 10^3
1 ≤ L ≤ N
L ≤ R ≤ N
- Operations are based on 1-indexing.
Note:
You are not required to print anything; it has already been handled. Implement the function to return the result.
Be the first one to answer
Add answer anonymously...
Top Morgan Stanley Java Developer interview questions & answers
Popular interview questions of Java Developer
>
Morgan Stanley Java Developer 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