AlgoDaily

Dollar Sign Deletion

Read at your own pace. Code execution, quizzes, progress tracking, and the AI tutor are available in the interactive view with JavaScript enabled.

Description

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:

String[] input = {"f$st", "st"};
isDollarDeleteEqual(input);
// true
// true because both become "st"
let input = ["f$st", "st"];
isDollarDeleteEqual(input);
// true
// true because both become "st"
input = ["f$st", "st"]
is_dollar_delete_equal(input)
# True
# True because both become 'st'
std::vector<std::string> input = {"f$st", "st"};
isDollarDeleteEqual(input);
// true
// true because both become "st"
string[] input = {"f$st", "st"};
IsDollarDeleteEqual(input);
// true
// true because both become "st"
input := []string{"f$st", "st"}
isDollarDeleteEqual(input)
// true
// 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
```js
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));
```
```java
public boolean isDollarDeleteEqual(String[] arr) {
  // Fill in this method
  return arr;
}

public String getFinalStr(String str) {
  // Fill in this method
  return str;
}

// String[] input = {"f$st", "st"};
// System.out.println(isDollarDeleteEqual(input));
```
```python
def is_dollar_delete_equal(arr):
  # Fill in this method
  return arr

def get_final_str(str):
  # Fill in this method
  return str

# input_arr = ["f$st", "st"]
# print(is_dollar_delete_equal(input_arr))
```
```cpp
bool isDollarDeleteEqual(string arr[]) {
  // Fill in this method
  return arr;
}

string getFinalStr(string str) {
  // Fill in this method
  return str;
}

//string input[] = {"f$st", "st"};
//cout << isDollarDeleteEqual(input);
```
```csharp
public bool IsDollarDeleteEqual(string[] arr) {
  // Fill in this method
  return arr;
}

public string GetFinalStr(string str) {
  // Fill in this method
  return str;
}

// string[] input = {"f$st", "st"};
// Console.WriteLine(IsDollarDeleteEqual(input));
```
```go
func isDollarDeleteEqual(arr []string) []string {
  // Fill in this method
  return arr
}

func getFinalStr(str string) string {
  // Fill in this method
  return str
}

//input := []string{"f$st", "st"}
//fmt.Println(isDollarDeleteEqual(input))
```

CONTINUE WITH ALGODAILY PREMIUM

Keep going with the complete tutorial.

Unlock the remaining explanations and exercises, alongside the full learning library.

Explore Premium →
Open interactive view →