Problem · Array

Compare Character Arrays with Backspaces

Learn this problem
EasyOdoo logoOdooFULLTIMEOA

Problem statement

You are given two arrays of string tokens, first and second. Each token is either a one-character string or the special token -b.

Process each array from left to right. A one-character token appends that character to the current text. The token -b removes the most recently appended character, if one exists. Return true if both arrays produce the same final text; otherwise, return false.

Function

areEqualAfterBackspaces(first: String[], second: String[]) → boolean

Examples

Example 1

first = ["a", "b", "-b", "c"]second = ["a", "c"]return = true

The first array produces ac: append a, append b, remove b, then append c. The second array also produces ac.

Example 2

first = ["-b", "a", "b"]second = ["a", "c"]return = false

The leading backspace has no effect, so the arrays produce ab and ac.

More Odoo problems

drafts saved locally
public boolean areEqualAfterBackspaces(String[] first, String[] second) {
  // Write your code here.
}
first["a", "b", "-b", "c"]
second["a", "c"]
expectedtrue
checking account