In it for each K Firstly, I saw whether or not it is visited
Then apply condition for i <= n && j <= m
and change i and j accordingly
According to me each loop will take O((m*n)/(k+1))
Can somebody find the reason for TLE
Thanks in advance
Convert all integer variable to long long int
@karangreat234 will help u.
KARAN Dm me
Firstly, there is no need for that as at max k = 10^6 which is in range
Secondly, I tried it
I think its because u are initialising the visited array each time .
Just initialise it one time and mark it unvisited in the loop after counting.