Here what I've tried implementing(bruteforce approach). I want to know if this is it the correct one to go for.