TUQ interview question

Solve this LeetCode Easy, then make it arbitrary.