Layer6 AI interview question

solve a leetcode question (easy-medium)