# Max In An Interval - Range Query #### Try First, Check Solution later

1. You should first read the question and watch the question video.
2. Think of a solution approach, then try and submit the question on editor tab.
3. We strongly advise you to watch the solution video for prescribed approach.

`You are given an array(of integers) of length n.You are required to answer q queries.In each query u are given an interval l, r both inclusive and u have to find the maximum element in this interval.To do the above task u have to create a datastructure as follows :-Implement the SegmentTree class:1. SegmentTree(int arr[]): Initializes the SegmentTree object with an array,2. int query(int l, int r): return max in interval [l, r].Can u do it in O(log(n)) or better Time Complexity.`
Input Format
`A number nn1n2.. n number of elementsA number qfollowing q lines contains queries of formatl r`
Output Format
`for each query print a single integer in seperate line`
Question Video
Constraints
`1. 1 <= n, q <= 10^52. 0 <= l <= r < n3. 10^9 <= arr[i] <= 10^94. all input and output will fit in 32bit signed integer`
Sample Input
`887425311040 70 32 71 6`
Sample Output
`108107`

• Related Topics

Run

Run
Id Name