You are viewing a single comment's thread. Return to all comments →
public static long candies(int n, List arr) { // Write your code here
long[] candies = new long[n]; Arrays.fill(candies, 1); for (int i=1; i<n; i++) { if (arr.get(i)>arr.get(i-1)) { candies[i] = candies[i-1]+1; } } for (int i=n-2; i>=0; i--) { if (arr.get(i)>arr.get(i+1)) { candies[i] = Math.max(candies[i], candies[i+1]+1); } } long sum = 0; for (long c : candies) { sum += c; } return sum; }``
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 →
public static long candies(int n, List arr) { // Write your code here