cswork / OA打开练习工作台

OnixOA #1

Get String to Remove

估计简单评测数据准备中,可先阅读题面

考点(AI 标注)字符串双指针滑窗

You are given a string S. You can use your mouse only once to place the mouse pointer on any position in the string and use the Backspace key on your keyboard. You have to determine if a string X can be obtained by performing such an operation. If it is possible, print the string that will be removed by using Backspace. Else, print -1. Note: You are allowed to press the Backspace key multiple times but not allowed to use the mouse more than one time. Function Description Complete the function getStringToRemove in the editor. getStringToRemove has the following parameters:

    1. String S: the original string
    1. String X: the target string to obtain Returns String: the string of characters that need to be removed to obtain the string X from S, if possible; otherwise, "-1"

Constraints

X.length ≤ S.length

Example 1

Input:

S = "InterviewMocha"
X = "IMocha"

Output:

"nterview"

Explanation: Placing the mouse pointer at w, and pressing the Backspace key 8 times, will convert the string InterviewMocha into the string IMocha. So, the string of characters that need to be removed to obtain the string X from S is nterview. Hence, the output is nterview.