Description
Solutions
Get String to Remove

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. 1. String S: the original string
  2. 2. 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"

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.
Constraints:

    X.length <= S.length

Thumbnail 0
Testcase

Result
Case 1

input:

output: