## 6 replies

Last post Mar 26, 2014 11:49 AM by Rion Williams

• shilpa.gurur...

Member

166 Points

157 Posts

### finding missing numbers from string value

Hi All,

string Num = "99100102103107"

Now, I have to write method for fetching missing number from this sequence. Kindly Help me.

Thanks

Shilpa

Warm Regards,
Shil
• thenaveenbha...

Member

10 Points

6 Posts

### Re: finding missing numbers from string value

Hey Shilpa,

Will you please be more specific what actually tring to do here.

Please mark your question as answered once you're past your problem, it saves other people time ... and I really want the points! ;-)
• Ashim Chatte...

Star

13650 Points

5477 Posts

### Re: finding missing numbers from string value

Mar 26, 2014 05:46 AM|Ashim Chatterjee|LINK

#### shilpa.gururao

Now, I have to write method for fetching missing number from this sequence

http://ajeetsingh.org/2013/08/20/given-a-string-of-numbers-in-sequence-order-find-the-missing-number-range-is-not-given/

Perplexity is the beginning of knowledge.
• shilpa.gurur...

Member

166 Points

157 Posts

### Re: finding missing numbers from string value

Hi,

values missing here are 101, 104, 105, 106. Programmatically I must determine all these values. How shall I do it?

Thanks

Shilpa

Warm Regards,
Shil
• markfitzme

All-Star

25891 Points

5831 Posts

### Re: finding missing numbers from string value

WIth this string, there really isn't any way. You can't say number 101 is missing without going through 1,2,3,4,5. Mixing and matching lenghts of options kills this possibility becase you can't determine two digit numbers such as 99 and determine three digit numbers like 100.

Don't forget to mark useful responses as Answer if they helped you towards a solution.
• asif iqbal

Member

465 Points

302 Posts

### Re: finding missing numbers from string value

Mar 26, 2014 11:39 AM|asif iqbal|LINK

the string values have to be comma separated or there should be some seaparation between the digitd to detemine the missing ones.

First, solve the problem. Then, write the code.

- Asif
• Rion William...

All-Star

113110 Points

18367 Posts

MVP

### Re: finding missing numbers from string value

Mar 26, 2014 11:49 AM|Rion Williams|LINK

Without actually knowing what your starting and ending numbers were, it would be impossible to simply determine which numbers were missing from the string (without some kind of delimiter to seperate the numbers).

If you knew the beginning and the end values, then it would be a bit easier to handle as seen below :

```public static List<int> GetMissingNumbers(string s, int start, int end)
{
// Build a list to populate with the missing values
List<int> missingValues = new List<int>();

// Iterate through your string and check if the current value exists
for(int i = start; i <= end; i++)
{
// If the string doesn't contain a stringified version of the number, add it
if(!s.Contains(i.ToString()))
{
}
}

// Return the missing values
return missingValues;
}```

which might be used as follows :

```// Your example input
string Num = "99100102103107";

// Get the numbers missing between 99 and 107 in the string
var missingNumbers = GetMissingNumbers(Num,99,107);

```101 was missing.