-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from AlgoWithMe/add-validparentheses
add validparentheses dsa question
- Loading branch information
Showing
5 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module validparentheses | ||
|
||
go 1.23.1 |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package validparentheses | ||
|
||
func ValidParentheses(input string) bool { | ||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} | ||
}) | ||
} | ||
} |