Given an array ↵
We need to find the count of all the elements in all the subarrays which are neither min nor max in that particular subarray↵
↵
eg ↵
↵
~~~~~↵
4↵
30 47 19 23↵
ans = 4↵
~~~~~↵
↵
~~~~~↵
i.e in 30 47219 count is 1 --> 30 is netiher max nor min↵
in 30 47 19 23 count is 2 --> 30 and 23 ↵
int 47 19 23 count is 1 --> 23 ↵
~~~~~↵
↵
~~~~~↵
3↵
11 20 17↵
ans = 1↵
~~~~~↵
↵
↵
~~~~~↵
We can have duplicate elements as input ↵
↵
n = 10^5 // size of array↵
~~~~~↵
↵
We need to find the count of all the elements in all the subarrays which are neither min nor max in that particular subarray↵
↵
eg ↵
↵
~~~~~↵
4↵
30 47 19 23↵
ans = 4↵
~~~~~↵
↵
~~~~~↵
i.e in 30 47
in 30 47 19 23 count is 2 --> 30 and 23 ↵
int 47 19 23 count is 1 --> 23 ↵
~~~~~↵
↵
~~~~~↵
3↵
11 20 17↵
ans = 1↵
~~~~~↵
↵
↵
~~~~~↵
We can have duplicate elements as input ↵
↵
n = 10^5 // size of array↵
~~~~~↵
↵