Dollar Sign Deletion (Medium)
Good morning! Here's our prompt for today.
You may see this problem at Palantir, Lyft, Goldman Sachs, Flatiron Health, Confluent, Asana, Pipedrive, Grammarly, Illumio, and Zoom.
You're given an array of strings containing alphabetical characters and certain $
characters. A $
represents a DELETE action whereby the character before it is deleted.
Each of these strings will be run through a method to operate on the $
DELETE action. We want to find out if the final string is the same for all of them. Let's take an example:
1let input = ["f$st", "st"];
2isDollarDeleteEqual(input);
3// true
4// true because both become "st"

Can you find a solution in O(n)
time and constant
space?
Constraints
- The input arrays can be of any size
- Every string has at least a single character
- The string will consist of dollar signs and lowercase alphabets
- Expected overall time complexity :
O(n)
- Expected space complexity :
O(n)
for good solution,O(1)
for asymptotically optimal solution
xxxxxxxxxx
49
var assert = require('assert');
function isDollarDeleteEqual(arr) {
// Fill in this method
return arr;
}
function getFinalStr(str) {
// Fill in this method
return str;
}
// const input = ["f$st", "st"];
// console.log(isDollarDeleteEqual(input));
try {
assert.equal(isDollarDeleteEqual(['f$ec', 'ec']), true);
console.log('PASSED: ' + "`['f$ec', 'ec']` should return `true`");
} catch (err) {
console.log(err);
}
try {
assert.equal(isDollarDeleteEqual(['a90$n$c$se', 'a90n$cse']), false);
console.log(
OUTPUT
Results will appear here.