Brinqa interview question

Assignment is bit Tough