Skip to content

Commit

Permalink
Merge pull request #7 from AlgoWithMe/add-validparentheses
Browse files Browse the repository at this point in the history
add validparentheses dsa question
  • Loading branch information
catdevman authored Sep 23, 2024
2 parents 13c3ca4 + 89d90d2 commit c4e72e5
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 0 deletions.
22 changes: 22 additions & 0 deletions go/validparentheses/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Problem Statement:
Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. An input string is valid if:

Open brackets must be closed by the same type of brackets.
Open brackets must be closed in the correct order.
Every close bracket has a corresponding open bracket of the same type.

# Example Inputs and Expected Outputs:
Example 1:

Input: s = "()"
Output: true

Example 2:

Input: s = "()[]{}"
Output: true

Example 3:

Input: s = "(]"
Output: false
3 changes: 3 additions & 0 deletions go/validparentheses/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module validparentheses

go 1.23.1
Binary file not shown.
5 changes: 5 additions & 0 deletions go/validparentheses/validparentheses.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package validparentheses

func ValidParentheses(input string) bool {
return false
}
34 changes: 34 additions & 0 deletions go/validparentheses/validparentheses_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package validparentheses

import (
"fmt"
"testing"
)

func TestValidParentheses(t *testing.T) {
tests := map[string]struct {
input string
expected bool
}{
"single": {
"()",
true,
},
"multiple pairs": {
"()[]{}",
true,
},
"mismatch": {
")[",
false,
},
}
for name, test := range tests {
t.Run(name, func(t *testing.T) {
out := ValidParentheses(test.input)
if out != test.expected {
t.Fatal(fmt.Sprintf("expected %t but got %t", test.expected, out))
}
})
}
}

0 comments on commit c4e72e5

Please sign in to comment.