IBM interview question

The OA asked two leetcode medium questions