Here is the link for the problem:(http://www.spoj.com/problems/HISTOGRA/) Here is my solution:(http://ideone.com/6SkfuH). The code is giving wrong output for the example mentioned in the solution link.The right answer for that test case is 283960245. I tried to debug my code and I think that the stack is not popping the value at i=2.I maybe wrong here,I am just not sure.Your help will be appreciated.