title: Find two numbers in array such that all elements between them is smaller than smallest of two number
body: <p>how to find pairs in array such that the elements which are between them are smaller than smallest element from the pair.</p>
  <p>Eg.<br />
  <strong>10 4 6 8 7</strong></p>
  <p>In the above pairs can be formed like:<br />
  (10,4), (4,6), (6,8), (8,7) <em>As there are no elements between them so it also works</em><br />
  (10,6) <em>As only elements between them is <strong>4</strong> and <strong>4 &lt; 6</strong> which is smallest of 10,6</em><br />
  (10, 8) * As <strong>4 &lt; 8</strong> and also <strong>6 &lt; 8</strong> *</p>
  <p>but (10,7) will <strong>not</strong> make pair as <strong>8 &gt; 7</strong></p>
  <p>All Pairs:</p>
  <p><strong>(10, 4), (4, 6), (6, 8), (8, 7), (10, 6), (10, 8)</strong></p>
  <p>My Code:</p>
  <pre><code>def findPirs(n, values):
      res = 0
      arr = []
      for start in range(n-1):
          currMax = 0
          for end in range(start+1, n):
              m = min(values[start], values[end])
              if currMax &lt; m:
                  arr.append((values[start], values[end]))
                  res += 1
              currMax = max(currMax, values[end])
  
      return res, arr
  </code></pre>
  <p>This is my current Code, it <em>works</em> <strong>but</strong> it is very inefficient, as it has <strong>O(n^2)</strong> Time complexity.<br />
  Any Suggestion on how to improve?</p>