C#: Verify that a string contains valid parentheses
Validate Brackets in String
A given string contains the bracket characters '(', ')', '{', '}', '<', ‘>', '[' and ']',
Write a C# programme to check the said string is valid or not. The input string will be valid when open brackets and closed brackets are same type of brackets.
Or
open brackets will be closed in proper order.
Sample Data:
( "<>") -> True
("<>()[]{}") -> True
("(<>") -> False
("[<>()[]{}]") -> True
Sample Solution-1:
C# Sharp Code:
Sample Output:
Original string: <> Verify the said string contains valid parentheses: True Original string: <>()[]{} Verify the said string contains valid parentheses: True Original string: (<> Verify the said string contains valid parentheses: False Original string: [<>()[]{}] Verify the said string contains valid parentheses: True
Flowchart:

Sample Solution-2:
C# Sharp Code:
Sample Output:
Original string: <> Verify the said string contains valid parentheses: True Original string: <>()[]{} Verify the said string contains valid parentheses: True Original string: (<> Verify the said string contains valid parentheses: False Original string: [<>()[]{}] Verify the said string contains valid parentheses: True
Flowchart:

C# Sharp Code Editor:
Previous C# Sharp Exercise: Find the longest common prefix from an array of strings.
Next C# Sharp Exercise: String with same characters .
What is the difficulty level of this exercise?