Get Max Deletions
A control device has 4 buttons that can be used to move a character around a screen in 4 directions: Up (U), Down (D), Left (L), and Right (R). The movement needs to be optimized by deleting unnecessary instructions while maintaining the same destination. Given the original set of instructions, what is the maximum number of instructions that can be deleted and still have the character reach the destination?
Note: The instructions that are deleted do not need to be contiguous.
Complete the function getMaxDeletions in the editor below.
getMaxDeletions has the following parameter:
- string S: the original instructions that were programmed
Returns
int: the maximum number of instructions that can be deleted from S while maintaining the destination
𓍯𓂃ᥫ᭡.Credit to chizzy_electᵕ̈𓏧🧡
1Example 1

2Example 2

Constraints
Limits and guarantees your solution can rely on.