SAP Interview Question

leetcode question (i think it was a leetcode easy)