Missing Number in Concatenated Sequence

You were given a sequence of consecutive nonnegative integers but missed one while appending them to create a string S. Your task is to identify the missing integer from this sequence.

If it is possible to form a sequence of consecutive integers by identifying the missing integer, then return that number. If the string is incorrectly formed with more than one missing integer, no missing integer, or the string is invalid, return -1.

Example:

Input:
T = 1
S = "1113"
Output:
12
Explanation:

The sequence was 11, 12, 13, but 12 was missed, leading to the string "1113".

Constraints:

  • 1 <= T <= 100
  • 1 <= |S| <= 104
  • The string S consists of digits 0 to 9
  • Numbers in the sequence have no more than six digits
  • Time Limit: 1 second

Note:

Ensure your solution correctly identifies the missing number or determines when to output -1.
AnswerBot
1y

The task is to find the missing number in a string of consecutive nonnegative integers.

  • Iterate through the string and check if each substring can form a valid number

  • If a substring forms a valid number...read more

Help your peers!
Add answer anonymously...
Amazon Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter