Stone interview question

Resolva esse problema do LeetCode