Incorrect text for test cases in Balanced Brackets question
See original GitHub issueMany of the test cases on the balanced brackets challenge state incorrect expectations. For example isBalanced("][")should return true.. There are many similar test cases like this.
The tests themselves seem to be correct despite the html text. It is worth noting however, that the test cases are missing at least one case that should be added. Please consider adding isBalanced("[]]]")should return false.
This case covers instances where:
- A stack approach is used to solve the problem.
- The programmer checks for an even number of characters before iterating.
- The programmer does not check for an empty stack before calling
.pop()
Example student code where the current tests pass but this case would fail:
function isBalanced(str) {
let matched = [];
if (str.length == 0) {
return true;
} else if (str.length % 2 != 0) {
return false;
} else {
for (let i = 0; i < str.length; i++) {
if (str[i] == "[") {
matched.push(str[i]);
} else {
matched.pop();
}
}
if (matched.length !== 0) {
return false;
}
return true;
}
}
Page with problem: https://learn.freecodecamp.org/coding-interview-prep/rosetta-code/balanced-brackets/
Tell us about your browser and operating system:
- Browser Name: Chrome
- Browser Version: 76.0.3809.100 (Official Build) (64-bit)
- Operating System: MacOS 10.13.6
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Check for Balanced Brackets in an expression (well ...
Given an expression string, write a program to examine whether the pairs and the orders of parentheses are balanced in expression or not....
Read more >Testing if Parenthesis are balanced, (a{[]b({})}c)[] returns false ...
From looking at the code, I think the problem is that your IsBalanced method returns false right away as soon as it runs...
Read more >Balanced Brackets Algorithm in Java - Baeldung
There are a couple of special cases to keep in mind: null is considered to be unbalanced, while the empty string is considered...
Read more >Valid Parentheses - LeetCode
Open brackets must be closed in the correct order. Every close bracket has a corresponding open bracket of the same type. Example 1:...
Read more >The valid parentheses problem - Educative.io
In case of a closing bracket, check if the stack is empty. If not, pop in a closing parenthesis if the top of...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

the ninth from the top…
isBalanced("[[][]]][") should return true.- removing the last[should catch the cases he is referring to - so it would becomeisBalanced("[[][]]]") should return false.@James-Crean Would you want to suggest a change for one of the tests?