Wipro interview question

Consecutive stone pile merge problem