Forward interview question

1 Leet Code Hard Question