Company: SAP Labs_16sep
Difficulty: medium
Longest Path in the Grid Problem Description You are given an N×M grid filled with numbers. A traveler starts from the top-left cell (1,1) and wants to reach the bottom-right cell (N,M). The traveler can only move down or right at each step. However, there is a rule: The traveler can only move to a cell containing a number greater than the number in the current cell. You need to determine the length of the longest possible path the traveler can take following these rules. If it is impossible to reach the bottom-right cell under these constraints, return -1. You must implement the function longestPathInGrid . Parameters: int N : The number of rows in the grid. int M : The number of columns in the grid. vector<vector<int>>& grid : A 2D vector representing the grid, where grid[i][j] is the number in the cell at row i and column j . Returns: int : The length of the longest path from the top-left cell to the bottom-right cell. Return -1 if there is no valid path. int longest