FastPrepCompare Character Arrays with Backspaces
Problems/Compare Character Arrays with Backspaces

Compare Character Arrays with Backspaces

Odoo logoOdoo● EasyFULLTIMEOA
QuestionFunctionExamples

Problem statement

Source note: The source describes character arrays while using the two-character backspace marker -b. The judged core task matches the report at about 98%.

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

  • Same Binary TreePHONE SCREEN · Seen Sep 2026
  • Employees Joined per MonthOA · Seen Sep 2024
  • Evaluate a Python Integer ExpressionOA · Seen Sep 2024
All Odoo interview questionsSee Odoo hiring insights
Saved
class Solution {
    public boolean areEqualAfterBackspaces(String[] first, String[] second) {
      // Write your code here.
    }
}
Checking account…