SAP interview question

leetcode question (i think it was a leetcode easy)