Given an array of list of commands U(Up), D(Down), L(Left) and R(Right) and initial cell position (x, y) in a matrix. Find the final cell position of the object in the matrix after following the given commands. It is assumed that the final required cell position exists in the matrix.
Examples:
Input : command[] = "DDLRULL"
x = 3, y = 4
Output : (1, 5)
Input : command[] = "LLRUUUDRRDDDULRLLUDUUR"
x = 6, y = 5
Output : (6, 3)
Source: Flipkart Interview (SDE-1 On Campus).
Approach: Following are the steps:
- Count cup, cdown, cleft and cright for U(Up), D(Down), L(Left) and R(Right) movements respectively.
- Calculate final_x = x + (cright – cleft) and final_y = y + (cdown – cup).
The final cell position is (final_x, final_y)



