You are viewing a single comment's thread. Return to all comments →

Ask yourself a few questions:

-The number of highest candles

-I need to know what the highest candle is.

-I need to know how many of them there are.

-Simple comparison should work for knowing what the highest is. Just store it in a var and reset when I find one that's bigger.

-Store the quantity in a var, increment it whenever I find one of the Highest candles and reset it each time I find a new highest candle.

Thank you Joseph, your explanation of the problem brouhgt me to this simple solution that run in O(n):

int ret = 0; int max = 0; for(int a : ar){ if(a > max){ ret = 1; max=a; } else if(a == max) ret++; } return ret;

Sometimes the hardest part of these problems is finding what the question is asking more than how to solve it.

## Birthday Cake Candles

You are viewing a single comment's thread. Return to all comments →

Ask yourself a few questions:

-The number of highest candles

-I need to know what the highest candle is.

-I need to know how many of them there are.

-Simple comparison should work for knowing what the highest is. Just store it in a var and reset when I find one that's bigger.

-Store the quantity in a var, increment it whenever I find one of the Highest candles and reset it each time I find a new highest candle.

Thank you Joseph, your explanation of the problem brouhgt me to this simple solution that run in O(n):

Sometimes the hardest part of these problems is finding what the question is asking more than how to solve it.