Find Missing Number In String Problem Statement

You have a sequence of consecutive nonnegative integers. By appending all integers end-to-end, you formed a string S without any separators. During this process, you accidentally omitted exactly one integer from the sequence. Given the string, your task is to find the missing integer.

If there is more than one missing integer, if all integers are present, or if the string is invalid, return -1.

Example:

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

The sequence 11, 12, 13 without one integer forms "1113" by missing 12.

Input:

T
S

Output:

Missing number for each test case

Constraints:

  • 1 <= T <= 100
  • 1 <= |S| <= 10^4
  • 0 <= S[i] <= 9

Note:

The numbers will have no more than six digits and consist of digits 0 to 9 only.
Be the first one to answer
Add answer anonymously...
Amazon Software Developer 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