SAP interview question

A small coding round from leetcode question