@keshavk said in Very Simple Java Solution with detail explanation:
here in this code if rating of earlier person is greater ,then we are comparing the candies....so if the number of candies of earlier one is "EQUAL OR LESS THAN" the i+ith....then it should be incremented....
below in inner if statement condition there shouldn't be "<=" ???
Brilliant idea and great solution! The approach to divide the ratings array into multiple independent yet connected cycles is elegant. The extra one candy added when newsign is 0 is actually to complement the highest bar of the previous cycle. And actually we don't have to do early return for array size 1, treating it as the last cycle is also ok.
The idea is brilliant! Increasing candy count during downhill traverse, the first kid in downhill gets candy count which is supposed to give the last kid in downhill, while the last kid in downhill gets candy count which is supposed to give the first kid in downhill, however the total sum for downhill is still the same.
NO. Although there are two while, the second while is to find the whole up or down sequence starting from i. At the end of the inner loop i=j. There is no overlap between two while. The total iteration won't be great than n .