Pocket Gems interview question

Leetcode questions two of them