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.
Created two arrays initialized to 1.
I scanned array left to right to find increasing trend, assigning 1 if it is smaller than left value or 1+left value if it is greater than left value. Then I scan array right to left to find decreasing trend and do the same. Then I find max of both values in both arrays and sum it.
Candies
You are viewing a single comment's thread. Return to all comments →
Passes all test cases!
Created two arrays initialized to 1. I scanned array left to right to find increasing trend, assigning 1 if it is smaller than left value or 1+left value if it is greater than left value. Then I scan array right to left to find decreasing trend and do the same. Then I find max of both values in both arrays and sum it.