No of sequence in an array.

I am trying to write a program that checks whether the number is in sequence(as in if the numbers are in order it is a sequence).
Ex: If the numbers are {1,2,3,6,7,8,9,10,11,13,15,17,20,21}, then, the underlined parts are a sequence. Now i want to find
1) the no of sequence in the array(in the above it is 3 )
2) the longest sequence (7to 11 which is 5). Please help me.
EDIT: Fixed, but really that's your doubt regarding this question lol :P
Last edited on
Why is 1,2,3,4 not a sequence?
You should write out in pseudo-code what you need to achieve, then translate it to code.

e.g
1
2
3
4
5
6
7
8
// set first number we expect to 1
// loop over the sequence
 // check if number is what we expect, if yes start sequence
 // if number is not what we expect, change number we expect to current number

 // if in sequence then add number to current sequence
 // if not in sequence, but we just were, count sequence length
 // number we expect + 1 


Something like that

Topic archived. No new replies allowed.