PDA

View Full Version : Generate 10 random no. and find longest length of increasing order without using arra


vishvendra
Jul 19, 2015, 01:19 AM
Like 23 43 45 46 58 29 30 31 15 17
in this series there are 3 increasing series which

23 43 45 46 58

29 30 31

15 17

longest inc. series is 23 43 45 46 58 . Which 5 consequently no. in increasing order .

AbstractJJJ
Sep 1, 2015, 05:27 PM
Well, you shouldn't have to store the numbers anywhere as you generate them. As you generate each number, you will keep track of 3 things.

1) The previous number you generated.
2) The length of the current series.
3) The maximum length of a series encountered so far.

If you encounter a number greater than the previously generated number than you increment the length of the current series.
Otherwise, if the current series length is greater, we'll set the max with this new value. Then, we'll start the length of the current series over for a new series of 1.
After that's all done, we'll set the current random number as the previous number and repeat.