Amazon Interview Question

basic dsa leetcode style with twist