0

Hello, can anyone clarifies this? I need to find consecutive segments that are odd or even. For example

2 6 5 = 2 and 6 = 2 consecutive even integers | 1 odd
4 6 8 1 3 = 4, 6, and 8 = 3 consecutive even integers | 1 and 3 consecutive odd integers 2
1 2 4 5 = 2 and 4 = 2 consecutive even integers | 1 odd
1 3 5 7 2 1 4 3 = 4 consecutive odd integers | 1 even

Edited by iceparticle.com

4
Contributors
5
Replies
32
Views
3 Years
Discussion Span
Last Post by sanjulovers
0

What would you expect as a result for the following sequence of integers?
1 2 3 6 7 8 11

0

Your last exampe, 1 3 5 7 2 1 4 3 is incorrect. It should be 4 odd, 2 even, 1 odd, 1 even, 1 odd.

And to answer niranga's question, the answer should be 1 odd, 1 even, 1 odd, 1 even, 1 odd, 1 even, 1 odd... :-)

Edited by rubberman

0

@rubberman
why is it 2 even? in 1 3 5 7 2 1 4 3
4 odd,2 even,1 odd,1 even,1 odd

for me this should be

1,3,5,7 = 4 odd
2 = 1 even
1 = 1 odd
4 = 1 even
3 = 1 odd

@niranga
1 2 3 6 7 8 11
1 = 1 odd
2 = 1 even
3 = 1 odd
6 = 1 even
7 = 1 odd
8 = 1 even
11 = 1 odd

thanks for your replies

0

So sorry for the late reply :-/
@rubberman: Thanks for the comment :)
@iceparticle.com : Did you manage to solve this?

0

INput all numbers to an array and then for each element check if it is odd or even.Then check if the next is of same category using a loop until a mismatch is found. Use a counter to count no of consecutive odds or evens. Then after a mismatch is found, Output as per your requirement and then resume the loop from where you found the mismatch. I hope this helped.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.