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.
that is exactly what I did. Does not seem complicated at all.
Pass one, you only consider the neighbour to the left and make sure, the current who has a higher score get at least one candy more than the left; Pass two, do in from right to left, check if the neighbour on the left who has a greater score gets at least one more than the right.
I think this is minimal because each element is only affected by its nearest neighbours, i.e., left and right, so two passes from different direction should make sure that the cost is minimal.
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 →
that is exactly what I did. Does not seem complicated at all.
Pass one, you only consider the neighbour to the left and make sure, the current who has a higher score get at least one candy more than the left; Pass two, do in from right to left, check if the neighbour on the left who has a greater score gets at least one more than the right.
I think this is minimal because each element is only affected by its nearest neighbours, i.e., left and right, so two passes from different direction should make sure that the cost is minimal.