Separate the Numbers

  • + 0 comments
    def separateNumbers(s):
        if s[0] == '0':
            print('NO')
            return
        
        for i in range(1,len(s)//2+1):
            p = 0
            k = 0
            fir = (0,i)
            x = s[fir[0]:fir[1]]
            while fir[1] < len(s):
                if re.match(r'9+$', s[fir[0]:fir[1]]):
                    p += 1
                sec = (fir[1], fir[1]+i+p)
                if int(s[fir[1]:fir[1]+i+p]) - int(s[fir[0]:fir[1]]) != 1:
                    break
                fir = sec
                k+=1
            else:
                print('YES', x)
                return
        print('NO')