Compare Character Arrays with Backspaces
Reported by candidates from Odoo's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Odoo reported this one in September 2024, and it looks friendlier than it is. Two token arrays, a special -b token, and a question about whether the final text matches. The input size is the catch. Building and comparing strings by brute force with repeated removals from the front or re-scanning can get ugly fast on big arrays. The clean answer is a stack or a backward two-pointer pass. If you blank mid-assessment, StealthCoder runs invisibly on your desktop as a safety net and hands you the solution in real time. Know the shape of it first and you probably won't need it.
The problem
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.
Reported by candidates. Source: FastPrep
Pattern and pitfall
This is the classic backspace string compare, just with tokens instead of a single string. The simple route: run each array through a stack. Push a character token, pop on -b if the stack isn't empty, then compare the two stacks. That's O(n + m) time and O(n + m) space. The pitfall is the leading backspace. Example 2 shows it: popping an empty stack must do nothing, so guard it. Another trap is treating -b as a two-character string to append, or comparing raw arrays without processing. If the interviewer wants O(1) space, go backward with two pointers and keep a skip counter for each array. Skip tokens while the counter is positive, then compare the next live characters. Either works. Pick the stack unless asked otherwise, since it's harder to get wrong. If your head goes blank on the pointer version, StealthCoder is the hedge on the live OA.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
You can drill Compare Character Arrays with Backspaces cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as backspace string compare. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Odoo's OA.
Odoo reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Compare Character Arrays with Backspaces FAQ
How hard is the Odoo backspace comparison problem really?+
Easy to medium. The stack approach is about ten lines. Most failures come from edge cases like a leading -b or an array that ends up empty, not from the algorithm. If you've seen the backspace string compare idea before, this is a quick one.
What's the trick to solving it fast?+
Simulate each array with a stack. Push characters, pop on -b only if the stack has something. Then compare the two resulting stacks or joined strings. Write one helper function and call it twice so you don't duplicate logic.
Can I solve it in O(1) extra space?+
Yes. Walk both arrays from the end with two pointers. Keep a backspace counter per array. When you see -b, increment it. When you see a character and the counter is positive, skip it and decrement. Otherwise compare it with the other side's next live character.
What edge cases should I test before submitting?+
Test a leading -b, multiple -b tokens in a row, more -b tokens than characters, and both arrays ending up empty, which should return true. Also test arrays of different lengths that still produce the same text, like Example 1.
How do I prepare for this in 48 hours?+
Do the stack version until you can write it without thinking, then do the two-pointer version once. Practice the empty-stack guard on purpose. That covers this problem and most of its variants, so you don't need a long prep plan.