Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Java (https://www.askmehelpdesk.com/forumdisplay.php?f=440)
-   -   Generate 10 random no. and find longest length of increasing order without using arra (https://www.askmehelpdesk.com/showthread.php?t=814273)

  • Jul 19, 2015, 01:19 AM
    vishvendra
    Generate 10 random no. and find longest length of increasing order without using arra
    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 .
  • Sep 1, 2015, 05:27 PM
    AbstractJJJ
    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.

  • All times are GMT -7. The time now is 03:11 AM.