Pape-Dawson interview question

solve leetcode question 234 using arrays