Problem · String

Character Reprogramming (Backend)

Learn this problem
EasyCanva logoCanvaINTERNOA

Problem statement

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.

Function

maxDeletions(s: String) → int

Examples

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
checking account