We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
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... :(
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Array Manipulation
You are viewing a single comment's thread. Return to all comments →
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... :(