Find next terms in sequences | Optiver Interview Question