GEARS

guyz please help me out here!!
i am doing this problem using dfs.
i am passing 4 cases in the first subtask and getting runtime error in the last
and i am getting tle for the secnd subtask!!
please help me out what algo should i use to reduce complexity!!
any inputs would be helpful
@aman whats your approach to the problem
Topic archived. No new replies allowed.