Problem · String

Character Reprogramming (Backend)

EasyCanvaINTERNOA

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.

Examples
01 · Example 1
s = "RRR"
return = 0
Example 1 illustration
There is nothing that can be deleted from these instructions, so the answer is 0.
More Canva problems
drafts saved locally
public int maxDeletions(String s) {
  // write your code here
}
s"RRR"
expected0
sign in to submit