Cyntexa Interview Question

Code optimisation and brute force both