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 hope this explanation helps you to understand algorithm.
If we draw a[]'s value into 'line graph', then the graph will looks like a mountain. (each a[n]'s value will indicate the height.)
Imagine the mountain tracking from left to right, and 'max' stores the maximum height.
starting point 'p' means go up / end point 'q+1' means go down.
then, just adding p and q+1, we can know the current height(which is 'x').
and what we need to do is just find the maximum height.
(oh, this website's image upload is very bad..)
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 hope this explanation helps you to understand algorithm.
If we draw a[]'s value into 'line graph', then the graph will looks like a mountain. (each a[n]'s value will indicate the height.)
Imagine the mountain tracking from left to right, and 'max' stores the maximum height.
starting point 'p' means go up / end point 'q+1' means go down. then, just adding p and q+1, we can know the current height(which is 'x'). and what we need to do is just find the maximum height.
(oh, this website's image upload is very bad..)