• + 1 comment

    I've realized I had to make two sequential loops to avoid timeout for a nested loop (as I did in the first time :) ). But I could not figure out, how to do that - I thought I had to keep track of ALL elements from the very beginning... As the approach above shows, it's enough to mark just the beginning of the 'increasing' interval and 'decreasing' interval at the first stage. Storing negative values was a bit unexpectful to me - I doubt I would figure this out myself. On next stage we fill the rest of elements and at the same time looking for the max element... Smart. But I lost this tour... :(