'Given 2 numbers N and Q followed by N numbers.Now Q inputs of 2 Numbers U and V are given. U indicates the starting index and V indicates the ending

Given 2 numbers N and Q followed by N numbers. Now Q inputs of 2 Numbers U and V are given. U indicates the starting index and V indicates the ending index. So for each U,V find the minimum of all values of the array from the index U to V(1 based indexing) Input Size: N<=100000 example

INPUT

5 3

1 1 1 1 1

1 3

2 4

3 4

OUTPUT

1

1

1



Solution 1:[1]

You can do something like this:

const N = 5;
const Q = 3;
const Numbers = [1, 1, 1, 1, 1];
const UVInputs = [[1, 3], [2, 4], [3, 4]];
const result = [];
for(let i = 0;i < Q;i++)
   result.push(Math.min(...Numbers.slice(UVInputs[i][0], UVInputs[i][1])));
console.log(result);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Yitbareck