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.
Your approach is correct but you have bad worded it here XO. Instead you can say that, make a count array of size n, initialized by 1.Now we have 2 arrays arr( rating array) and count array. Now we go from left to right in count array and if(arr[i+1]>arr[i]) count[i+1]=count[i]+1 . Now we go from right to left if(arr[i-1] > arr[i] ) and count[i-1] <= count[i] then count[i-1] =count[i] +1. Then just calculate the sum of count array i.e your answer.
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 →
Your approach is correct but you have bad worded it here XO. Instead you can say that, make a count array of size n, initialized by 1.Now we have 2 arrays arr( rating array) and count array. Now we go from left to right in count array and if(arr[i+1]>arr[i]) count[i+1]=count[i]+1 . Now we go from right to left if(arr[i-1] > arr[i] ) and count[i-1] <= count[i] then count[i-1] =count[i] +1. Then just calculate the sum of count array i.e your answer.