You are viewing a single comment's thread. Return to all comments →
Ans to this case is 22. here is my code passed all test cases. [ please for plagiarism policy ]
long candies(int n, vector<int> arr) { vector<int> candyLeft(arr.size(),1); vector<int> candyRight(arr.size(),1); long count=0; for(int i=1;i<arr.size();i++){ if(arr[i]>arr[i-1]){ candyLeft[i]=candyLeft[i-1]+1; } } for(int i=arr.size()-1;i>=0;--i){ if(arr[i]>arr[i+1]){ candyRight[i]=candyRight[i+1]+1; } } for(int i=0;i<arr.size();i++){ candyLeft[i]=max(candyLeft[i],candyRight[i]); }
for(int i=0;i<arr.size();i++){ count+=candyLeft[i]; } return count;
}
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 →
Ans to this case is 22. here is my code passed all test cases. [ please for plagiarism policy ]
}