REX interview question

Mostly leetcode Medium