Cyntexa interview question

Code optimisation and brute force both