title: Python: Longest Plateau Problem: to find the length and location of the longest contiguous sequence of equal values
body: <p>The question is to solve the following question in Sedgewick Wayne's Python book:</p>
  
  <p>Given an array of integers, compose a program that finds the length and location of the longest contiguous sequence of equal values where the values of the elements just before and just after this sequence are smaller.</p>
  
  <p>I tried on this problem, and encountered some problems.</p>
  
  <p>Here are my codes:</p>
  
  <pre><code>import sys
  import stdio
  
  # Ask the user input for the list of integers
  numList = list(sys.argv[1])
  
  maxcount = 0
  value = None
  location = None
  
  i = 1
  while i &lt; len(numList) - 1:
      resList = []
      count = 0
      # If i &gt; i-1, then we start taking i into the resList
      if numList[i] &gt; numList[i - 1]:
          # start counting
          resList += [numList[i]]
          # Iterating through the rest of the numbers
          j = i + 1
          while j &lt; len(numList):
              # If the j element equals the i, then append it to resList
              if numList[i] == numList[j]:
                  resList += [numList[j]]
                  j += 1
              elif numList[i] &lt; numList[j]:
                  # if j element is greater than i, break out the loop
                  i = j
                  break
              else:
                  # if j element is smaller than i, count equals length of resList
                  count = len(resList)
                  if count &gt; maxcount:
                      maxcount = count
                      value = resList[1]
                      location = i
                  i = j
      else:
          # if not greater than the previous one, increment by 1
          i += 1
  
  stdio.writeln("The longest continuous plateau is at location: " + str(location))
  stdio.writeln("Length is: " + str(maxcount))
  stdio.writeln("Number is: " + str(value))
  </code></pre>
  
  <p>The result shows:</p>
  
  <pre><code>python exercise1_4_21.py 553223334445554
  The longest continuous plateau is at location: 11
  Length is: 3
  Number is: 5
  
  
  python exercise1_4_21.py 1234567
  The longest continuous plateau is at location: None
  Length is: 0
  Number is: None
  </code></pre>
  
  <p>But somehow, if the list given is in the format of having a group of continuous integers that is greater than the previous one, but then this group ends the list with no integer following it, my program simply doesn't end....</p>
  
  <pre><code>exercise1_4_21.py 11112222111444
  Traceback (most recent call last):
    File "exercise1_4_21.py", line 32, in &lt;module&gt;
      if numList[i] == numList[j]:
  KeyboardInterrupt
  
  
  exercise1_4_21.py 111222211112223333
  Traceback (most recent call last):
    File "exercise1_4_21.py", line 25, in &lt;module&gt;
      if numList[i] &gt; numList[i - 1]:
  KeyboardInterrupt
  </code></pre>
  
  <p>Not quite sure where the logical error is...thank you very much for your help and kindness!</p>