“Given a N∗M matrix of numbers from 1 to N∗M(each number occurs only once), find a path from top left to right bottom while moving right or down only. If we sort all values visited in this path it should be lexico-graphically smallest.”
"Given a N∗M matrix of numbers from 1 to N∗M(each number occurs only once), find a path from top left to right bottom while moving right or down only. If we sort all values visited in this path it should be lexico-graphically smallest."
hello @Kash-Moulik-3715574511847721
this one is simple bactracking problem.
to find lexicographical smallest path. u just have to take care of ur function calling order.
if u r at (x,y) then from here u can go to (x+1,y) or (x,y+1)
now which one to choose?
chose that cell which has minimum value and check whether path exist from that choosen cell or not. it exist then simply return
otherwise choose othercell and find path from that choosen cell