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.

AnswerBot
4mo

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

Help your peers!
Select
Add answer anonymously...

Optum Global Solutions Associate Software Engineer interview questions & answers

An Associate Software Engineer was asked 12mo agoQ. How will you approach a problem which you are completely unaware of?
An Associate Software Engineer was asked Q. Given a string s, reverse the order of words in the string.
An Associate Software Engineer was asked Q. Given the head of a singly linked list, return the middle node of the linked lis...read more

Popular interview questions of Associate Software Engineer

An Associate Software Engineer was asked 11mo agoQ1. How will you approach a problem which you are completely unaware of?
An Associate Software Engineer was asked Q2. Given a string s, reverse the order of words in the string.
An Associate Software Engineer was asked Q3. Given the head of a singly linked list, return the middle node of the linked lis...read more
Optum Global Solutions Associate Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits