
Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
What if we sort each cell of the matrix by the value?
Don't include small values in your path if you can only include large values.
Let's keep adding a possible cell to use in the path incrementally with decreasing values.
If the start and end cells are connected then we don't need to add more cells.
Use union-find data structure to check connectivity and return as answer the value of the given cell that makes start and end cells connected.