title: Maximum days to light candles
body: <p>You are given heights of n candles. First day you lit one candle Second day you   need to lit two candles Third day you need to lit three candles till possible. After lighting candles the height of candles deduced by 1 each day.You can also extinguish any candle you want but only at the end of day. So you need to tell the maximum number number of days , you can carry on lighting the candles.  </p>
  
  <pre><code>Example : there are three candles of heights {2 ,2 ,2 }  
  Answer : 3  
  1.You light first candle on day one. heights -&gt; {1,2,2}  
  2.You light second and third and extinguish first one . heights -&gt;{1, 1,1}  
  3.You light all the candles. heights -{0,0,0}  
  </code></pre>
  
  <p>I found the solution on one blog as:  </p>
  
  <p>Sort the array.Start from the maximum each day we add an element and subtract the number of candles needed. So for 2,2,2    </p>
  
  <pre><code>Day 1: 2-1 = 1 Day 2: 1+2-2 = 1 Day 3: 1+2-3 = 0  
  Answer is: 3  
  But for 1,1,1 this algorithm will fail as answer should be 2.  
  </code></pre>
  
  <p>Please help me with this problem.  </p>