title: Finding the longest substring of repeating characters in a string
body: <p>(this is the basis for <a href="http://codeforces.com/problemset/gymProblem/101306/A" rel="nofollow noreferrer">this codeforces problem</a>)</p>
  
  <p>I try not to get help with codeforces problems unless i'm really, really, stuck, which happens to be now.</p>
  
  <blockquote>
  Your first mission is to find the password of the Martian database. To achieve this, your best secret agents have already discovered the following facts:
  
  The password is a substring of a given string composed of a sequence of non-decreasing digits
  The password is as long as possible
  The password is always a palindrome
  A palindrome is a string that reads the same backwards. racecar, bob, and noon are famous examples.
  
  Given those facts, can you find all possible passwords of the database?
  
  Input
  The first line contains n, the length of the input string (1 ≤ n ≤ 105).
  
  The next line contains a string of length n. Every character of this string is a digit.
  
  The digits in the string are in non-decreasing order.
  
  Output
  On the first line, print the number of possible passwords, k.
  
  On the next k lines, print the possible passwords in alphabetical order.
  </blockquote>
  
  <p>My observations are:</p>
  
  <ol>
  <li><p>A palindrome in a non-decreasing string is simply a string of repeating characters (eg. "4444" or "11" ) </p></li>
  <li><p>on character <code>i</code>, the last instance of i - the first instance of i +1 = length of the repeating character</p></li>
  <li><p>Keeping track of the max password length and then filtering out every item that is shorter than the max password length guarantees that the passwords outputted are of max length</p></li>
  </ol>
  
  <p>my solution based on these observations is:</p>
  
  <pre><code>n,s = [input() for i in range(2)]#input
  
  maxlength = 0
  
  results = []
  
  
  for i in s:
      length = (s.rfind(i)-s.find(i))+1 
  
      if int(i*(length)) not in results and length&gt;=maxlength:
  
          results.append(int(i*(length))) 
  
          maxlength = length 
  
  
  
  #filer everything lower than the max password length out
  results = [i for i in results if len(str(i))&gt;=maxlength]
  
  
  #output
  print(len(results))
  
  for y in results:
      print(y)
  </code></pre>
  
  <p>unfortunately, this solution is wrong, in fact and fails on the 4th test case. I do not understand what is wrong with the code, and so i cannot fix it. Can someone help with this? </p>
  
  <p>Thanks for reading!</p>