Separate the Numbers

  • + 0 comments

    There is my solution in python all TCs are pass but I don't know why TC number 6 still fail eventhough my result and expected are the same

    Input:

    10
    73747576777879808182838485868788
    73747576777879808182838485868778
    29303132333435363738394041424344
    29303132333435363738394041424244
    16171819202122232425262728293031
    16171819202122232425262728292031
    60616263646566676869707172737475
    60616263646566676869707172727475
    90919293949596979899100101102103
    90919293949596979899100101002103
    

    Expected

    YES 73
    NO
    YES 29
    NO
    YES 16
    NO
    YES 60
    NO
    YES 90
    NO
    

    My code

    def separateNumbers(s):
        digit = 1
        l = len(s)
        check = False
        res = int(s)
    
        start = 0
        while start + digit < l and digit <= l // 2:
            first_num = int(s[start : start + digit])
            
            if len(str(first_num)) == len(str(first_num + 1)):
                end = start + digit * 2
                start += digit
            else:
                end = start + (digit * 2) + 1
                start += digit
                digit += 1
            
            second_num = int(s[start : end])
            
            # Checking leading 0
            if s[start : end][0] == '0':
                digit += 1
                start = 0
                continue
            
                
            if first_num + 1 == second_num:
                res = min(first_num, res)
                if end == l:
                    check = True
            else:
                res = int(s)
                start = 0
                if len(str(first_num)) == len(str(first_num + 1)):
                    digit += 1
                
        if check == True:
            print('YES' + ' ' + str(res))
        else:
            print('NO')