Find the missing no in string
Submissions: 949   Accuracy:


  Difficulty: Medium   Marks: 4

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 complete the function missingNumber which return's the missing number. The numbers will have no more than six digits. Print -1 if input sequence is not valid.

Note: Its is guaranteed that if the string is valid, then it is sure that atleast one number would be missing from the string.

The first line of input contains an integer T denoting the no of test cases. Then T test cases follow. Each test case contains an string s representing a number.

For each test case in a new line output will be the missing number. Output will be -1 if the input is invalid.

1<=Length of string<=100

Example(To be used only for expected output):




Note:The Input/Ouput format and Example given are used for system's internal purpose, and should be used by a user for Expected Output only. As it is a function problem, hence a user should not read any input from stdin/console. The task is to complete the function specified, and not to write the full code.

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Harshit Sidhwa
Author: harshitsidhwa

Need help with your code? Please use, generate link and share the link here.

to report an issue on this page.