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.
Nothing magic. Decreasing sequences have to descrease down to 1. And increasing sequences have to increase from 1. Reverse iteration or keeping two last value variables will do the job. The tricky point is determining values at the joint of increasing and decreasing values. Values at joint points can be determined after second iteration, say reverse, greater value will be kept of two iterations in joints.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Candies
You are viewing a single comment's thread. Return to all comments →
Nothing magic. Decreasing sequences have to descrease down to 1. And increasing sequences have to increase from 1. Reverse iteration or keeping two last value variables will do the job. The tricky point is determining values at the joint of increasing and decreasing values. Values at joint points can be determined after second iteration, say reverse, greater value will be kept of two iterations in joints.