title: Count the segments where a[i] is rightmost or leftmost and is max
body: <p>You are given an array containing <code>N</code> integers and you have to answer <code>K</code> queries. Each query contains an integer <code>X</code> which is the index of the (1 based index) element of the array.<br />
  Calculate the following for each query:</p>
  <pre><code>The number of segments containing the index X as the leftmost or the 
  rightmost element and the number at the index `X` is `&gt;=` each element
  of that segment.
  </code></pre>
  <p>Segment formation example:<br />
  You have array <code>{1, 2, 3}</code>.
  The possible segments for <code>3</code> are <code>[2,3]</code> and <code>[1,2,3]</code> and <code>[3]</code>.<br />
  The possible segments for 2 are <code>[2]</code> and <code>[1,2]</code><br />
  I got solution by brute force. Worst case Time Complexity is <code>O(n * k)</code></p>
  <pre><code>Input: Array[] = {4,2,1,3}, Queries[] = {1,4}
  Output:  
  4  
  3
  
  Explanation: 
  For first query 1 all possible valid segments are [4], [4,2] , [4,2,1] and [4,2,1,3] 
  hence answer is 4.  
  For second query 4 all possible valid segments are [3], [1,3] and [2,1,3]
  hence answer is 3.
  </code></pre>