Find the missing number in a string of numbers with no separator | Python3 program to find a missing number in a string of consecutive numbers without any separator . ; gets the integer at position i with length m , returns it or - 1 , if none ; Find value at index i and length m . ; Returns value of missing number ; Try all lengths for first number ; Get value of first number with current length ; To store missing number of current length ; To indicate whether the sequence failed anywhere for current length . ; Find subsequent numbers with previous number as n ; If we haven 't yet found  the missing number for  current length. Next  number is n+2. Note  that we use Log10 as  (n+2) may have more  length than n. ; If next value is ( n + 1 ) ; not found or no missing number ; Driver code
import math NEW_LINE MAX_DIGITS = 6 NEW_LINE def getValue ( Str , i , m ) : NEW_LINE INDENT if ( i + m > len ( Str ) ) : NEW_LINE INDENT return - 1 NEW_LINE DEDENT value = 0 NEW_LINE for j in range ( m ) : NEW_LINE INDENT c = ( ord ( Str [ i + j ] ) - ord ( '0' ) ) NEW_LINE if ( c < 0 or c > 9 ) : NEW_LINE INDENT return - 1 NEW_LINE DEDENT value = value * 10 + c NEW_LINE DEDENT return value NEW_LINE DEDENT def findMissingNumber ( Str ) : NEW_LINE INDENT for m in range ( 1 , MAX_DIGITS + 1 ) : NEW_LINE INDENT n = getValue ( Str , 0 , m ) NEW_LINE if ( n == - 1 ) : NEW_LINE INDENT break NEW_LINE DEDENT missingNo = - 1 NEW_LINE fail = False NEW_LINE i = m NEW_LINE while ( i != len ( Str ) ) : NEW_LINE INDENT if ( ( missingNo == - 1 ) and ( getValue ( Str , i , 1 + int ( math . log10 ( n + 2 ) ) ) == n + 2 ) ) : NEW_LINE INDENT missingNo = n + 1 NEW_LINE n += 2 NEW_LINE DEDENT elif ( ( getValue ( Str , i , 1 + int ( math . log10 ( n + 1 ) ) ) == n + 1 ) ) : NEW_LINE INDENT n += 1 NEW_LINE DEDENT else : NEW_LINE INDENT fail = True NEW_LINE break NEW_LINE DEDENT i += 1 + int ( math . log10 ( n ) ) NEW_LINE DEDENT if ( not fail ) : NEW_LINE INDENT return missingNo NEW_LINE DEDENT DEDENT return - 1 NEW_LINE DEDENT print ( findMissingNumber ( "99101102" ) ) NEW_LINE