### Dollar Sign Deletion (Main Thread)

Here is the interview question prompt, presented for reference.

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:

``````const input = ["f\$st", "st"]
isDollarDeleteEqual(input);
// true
// true because both become "st"
``````

Given the below function signature, can you find a solution in O(n) time and constant space?

``````function isDollarDeleteEqual(arr) {
return;
}
``````

### 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)`

You can see the full challenge with visuals at this link.

Challenges â€¢ Asked almost 2 years ago by Hardik

Jake from AlgoDaily Commented on Sep 04, 2019:

This is the main discussion thread generated for Dollar Sign Deletion.

Hardik Commented on Sep 04, 2019:

Test case 1 and 2 are both same yet it is shown that their results are different.

lazycoder Commented on Mar 11, 2020:

['f\$ec', 'ec'] should return true

['f\$ec', 'ec'] should return false
These 2 test cases are contradictory.

Rahat Zaman Commented on Feb 05, 2021:

Yes, we have now fixed this problem.

yorkcook13 Commented on Mar 24, 2021:

I can't figure out why my code doesn't work. It works when I try it in repl.it, is it because it doesn't make the time constraint?? Thanks!

function isDollarDeleteEqual(arr) {
let mapped = arr.map(item => getFinalStr(item));
return mapped.every(item => item === mapped[0]);
}
function getFinalStr(str) {
let arr = str.split('');

for(i =0; i < arr.length; i++) {
if(arr[i] === '\$') {
arr.splice(i-1, 2);

}
}
return arr.join('');
}