SAP interview question

Two leetcode medium questions, 90 minutes.