[Solution] Interesting Subarray CodeChef Solution
Problem
You are given an array of length .
The interesting value of a subarray is defined as the product of the maximum and minimum elements of the subarray.
Find the minimum and maximum interesting value over all subarrays for the given array.
Note: A subarray is obtained by deletion of several (possibly zero) elements from the beginning of the array and several (possibly zero) elements from the end of the array.
Input Format
- The first line of input will contain a single integer , denoting the number of test cases.
- The first line of each test case contains an integer - the length of the array .
- The second line of each test case contains space-separated integers .
Output Format
For each test case, output two space-separated integers on a new line the minimum and maximum interesting value over all subarrays for the given array.
Explanation:
Test case : The minimum interesting value possible is . A subarray with interesting value equal to is . Here, both minimum and maximum elements of the subarray are . It can be proven that no subarray of the array has interesting value less than .
The maximum interesting value possible is . A subarray with interesting value equal to is . Here, both minimum and maximum elements of the subarray are . It can be proven that no subarray of the array has interesting value greater than .
Test case : The minimum interesting value possible is . A subarray with interesting value equal to is . Here, minimum element is and maximum element is . It can be proven that no subarray of the array has interesting value less than .
The maximum interesting value possible is . A subarray with interesting value equal to is . Here, both minimum and maximum elements of the subarray are . It can be proven that no subarray of the array has interesting value more than .
No comments:
Post a Comment