Description
Solutions
Submission
Character Reprogramming (Backend)
🤘 INTERN

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.

Example 1:

Input:  s = "RRR"
Output: 0
Explanation:
There is nothing that can be deleted from these instructions, so the answer is 0.
Constraints:
    N/A
Thumbnail 0
Testcase

Result
Case 1

input:

output: