Thoughtworks Interview Question

The most difficult part was both logic and code test.