Apple Interview Question

a twist on Leet code problem