Teradata interview question

Solve a hacker rank problem about link list