title: Increasing Sequence from two arrays
body: <p>You are given two list of integers a and b of same length n.</p>
  <p>find the count of strictly increasing sequences of integers <code>i[0] &lt; i[1] &lt; ... &lt; i[n-1]</code> such that</p>
  <p><code>min(a[i], b[i]) &lt;= i[i] &lt;= max(a[i], b[i])</code> for each <code>i</code>.</p>
  <p>example</p>
  <p>input:</p>
  <pre><code>a= [1,3,1,6]
  b= [6,5,4,4]
  </code></pre>
  <p>Output:</p>
  <pre><code>4
  </code></pre>
  <p>the four sequences  will be :</p>
  <pre><code>[1,3,4,5]
  [1,3,4,6]
  [2,3,4,5]
  [2,3,4,5]
  </code></pre>
  <p>Here's what I tried</p>
  <pre><code>a=[1,3,1,6]
  b=[6,5,4,4]
  P=[]
  for i in range(len(a)):
      if i&lt;len(a)-1:
          if max(a[i],b[i])&gt;=max(a[i+1],b[i+1]):
              P.append([x for x in range(min(a[i],b[i]),min(max(a[i],b[i]),max(a[i+1],b[i+1])))])
          else:
              P.append([x for x in range(min(a[i],b[i]),1+min(max(a[i],b[i]),max(a[i+1],b[i+1])))])
      else:
          P.append([x for x in range(min(a[i],b[i]),max(a[i],b[i])+1)])
  for i in range(len(a)):
      if i&lt;len(a)-1 and P[i+1][-1]&lt;=P[i][-1]:
          P[i]=[x for x in range(P[i][0],P[i+1][-1])]
      if i&gt;0 and P[i][0]&lt;=P[i-1][0]:
          P[i]=[x for x in range(P[i-1][0]+1,1+P[i][-1])
  
  cnt=1
  for i in P:
      cnt*=len(i)
  print(cnt)
  </code></pre>
  <p>What I did is that I took this setup</p>
  <pre><code>1 2 3 4 5 6
      3 4 5 
  1 2 3 4
        4 5 6 
  </code></pre>
  <p>and reduced it to this</p>
  <pre><code>1 2
     3 
      4 
        5 6 
  </code></pre>
  <p>removing all numbers that wouldn't make it to the sequence.</p>
  <p>Now what I do is, Just multiply the len of each row-wise sequence.
  The problem arises when there is a case such as this.</p>
  <pre><code>1 2 3
      3 4
        4 5
          5 6 
  </code></pre>
  <p>Now the simple multiplication of the lengths doesn't hold up.
  This is where I am stuck.</p>