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.
- Prepare
- Algorithms
- Greedy
- Candies
- Discussions
Candies
Candies
Sort by
recency
|
658 Discussions
|
Please Login in order to post a comment
Why the result of Sample Input 1 is 19? 1,2,1,2,1,2,3,4,2,1. After 4 should be 1, I do not understood why is 2.
Can anyone please tell me what is wrong in my code. only 2 test cases are passing.
if(n==1) { return 1; } List out = new ArrayList (); int counter =1; out.add(counter); for(int i=0 ; i arr.get(i)) { counter++; out.add(counter); } else{ counter=1; out.add(counter); } } // System.out.println(out); return out.stream().mapToInt(Integer::intValue).sum();
The description isn't very clear on the definition of "if two children sit next to each other". From the examples it looks amost like the number of candies each kid has is used to determine the position of the seat.
arr = [2,4,2,6,1,7,8,9,2,1]
ans = 1,2,1,2,1,2,3,4,2,1
I dont understand where we get 3 and 4 out of no where? ok 4 is more + 1 than 3, but why 3? and why start at 8? why not 2,6 get 3 and 4 ?