Thoughtworks Interview Question

First and second were coding rounds