Good morning! Here's our prompt for today.
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:
1input := []string{"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
Try to solve this here or in Interactive Mode.
How do I practice this challenge?
xxxxxxxxxx51
​package main​import (  "fmt")​func isDollarSignEqual(slice []string) bool {  // fill in this function  return true}func main() {  slice := []string{"b$$p", "$b$p"}  fmt.Println(isDollarSignEqual(slice))​  // test cases start  fmt.Printf("============================================================\n")  passed := true  if isDollarSignEqual([]string{"f$ec", "ec"}) == true {    fmt.Println("TEST 1 --- PASSED")  } else {    fmt.Println("TEST 1 --- FAILED : got ", isDollarSignEqual([]string{"f$ec", "ec"}), " expected true")    passed = false  }  if isDollarSignEqual([]string{"a90$n$c$se", "a90n$cse"}) == false {    fmt.Println("TEST 2 --- PASSED")  } else {    fmt.Println("TEST 2 --- FAILED : got ", isDollarSignEqual([]string{"a90$n$c$se", "a90n$cse"}), " expected false")    passed = false  }OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment
Here's our guided, illustrated walk-through.
How do I use this guide?
Access all course materials today
The rest of this tutorial's contents are only available for premium members. Please explore your options at the link below.


