Start by opening this URL and reading through the problem https://github.com/turingschool/challenges/blob/master/well_formed_strings.markdown
Make sure you iterate from simple cases to more complex cases If you get done with the example cases, consider the "edge cases", for example: What about an empty "" input? What about just a close ")"? What about too many closes "())" Are any other characters allowed like "( [ ] )"? Pay careful attention to the JavaScript/Ruby test cases. If you finish early, work on the extension problem as well.
The problem seems pretty straight forward, however, I bet the solution will be more complex than it appears. I believe I will need to leverage a stack
data structure with conditionals to solve this challenge.
I plan to use the stack
data structure with conditional statements to solve this code challenge. I learned yesterday that a stack is easy to implement with an array. I can use push and/or pop to easily remove elements from the end of the array. One con to using a stack would be the fact that it's more expensive in memory, however, for a challenge this small, this should not be an issue.
- create a variable for my stack
- create a template object that includes keys of the opening symbol for parenthesis and values that are their closing counterparts
- iterate using a
for
loop to check if the string coming in has either a(
,{
, or[
, and if so, I will push it into the stack array, otherwise I will pop from the stack array - if the last element left in the array after all iterating is done is odd, I will return false, otherwise, I will return true
I believe the Big O complexity for my solution would be O(n) linear because it is doing a simple iteration through the string using a for
loop