Minimum Direction Changes Problem Statement
Given a 2D grid with 'N' rows and 'M' columns, where each cell contains a character from the set { 'U', 'L', 'D', 'R' } indicating the allowed direction to move to a neighboring cell, determine the minimum number of cells that need to be changed to create a valid path from the top-left to the bottom-right corner of the grid.
Input:
T
N M
grid[0][0] grid[0][1] ... grid[0][M-1]
...
grid[N-1][0] grid[N-1][1] ... grid[N-1][M-1]
Output:
Minimum number of direction changes to create the path for each test case.
Example:
Input:
1
2 2
R D
L D
Output:
0
Explanation:
The given grid allows a direct path from top-left to bottom-right following the directions without any changes.
Constraints:
1 ≤ T ≤ 10
1 ≤ N, M ≤ 100
- Each cell contains one of {'U', 'L', 'D', 'R'}.
- Time Limit: 1 second
Note:
You do not need to handle input/output. Implement the function and return the result.


The problem involves finding the minimum number of direction changes needed to create a valid path from the top-left to the bottom-right corner of a 2D grid.
Create a graph representation of the grid w...read more

Top Optum Global Solutions Associate Software Engineer interview questions & answers
Popular interview questions of Associate Software Engineer
Top HR questions asked in Optum Global Solutions Associate Software Engineer
Reviews
Interviews
Salaries
Users/Month