VOOZH about

URL: https://www.geeksforgeeks.org/dsa/find-missing-number-string-numbers-no-separator/

⇱ Find the missing number in a string of numbers with no separator - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Find the missing number in a string of numbers with no separator

Last Updated : 23 Jul, 2025

Given a string consisting of some numbers, not separated by any separator. The numbers are positive integers and the sequence increases by one at each number except the missing number. The task is to find the missing number. The numbers will have no more than six digits. Print -1 if the input sequence is not valid. 

Examples: 

Input : 89101113
Output : 12

Input : 9899101102
Output : 100

Input : 596597598600601602:
Output : 599

Input : 909192939495969798100101
Output : 99

Input : 11111211311411511
Output : -1

The idea is to try all lengths from 1 to 6. For every length we try, we check if the current length satisfies the property of all consecutive numbers and one missing. An interesting thing is the number of digits may change as we increment numbers. For example when we move to 100 from 99. To handle this situation, we find the number of digits using log base 10.

Below is the implementation of the above approach: 


Output
100
Comment
Article Tags: