can some one explain how to approach this problem. I am solving it with Brute force which gives TLE.
Problem
My code :