fork download
  1. sequence = '112222555555444'
  2.  
  3. max_len = -1
  4. tmp_len = 0
  5. end_index = 0
  6. prew_value = -1
  7.  
  8. for index, value in enumerate(sequence):
  9. if value != prew_value:
  10. if tmp_len > max_len:
  11. max_len = tmp_len
  12. end_index = index
  13. tmp_len = 1
  14. prew_value = value
  15. else:
  16. tmp_len += 1
  17.  
  18. print ("{} from {} to {}".format(sequence[end_index - max_len: end_index], end_index - max_len, end_index))
Success #stdin #stdout 0.02s 9936KB
stdin
Standard input is empty
stdout
555555 from 6 to 12