Good morning! Here's our prompt for today.
As a software engineer, you'll often be asked to optimize programs. One of the easiest ways to do so is by the introduction of an additional data structure.
Here's another classic problem along the same vein. We're provided a string like the following: "{[])}"
that is inclusive of the following symbols:
- parentheses '()'
- brackets '[]', and
- curly braces '{}'.
Can you write a function that will check if the symbol pairings in the string follow these below conditions?
- They are correctly ordered, meaning opening braces/symbols should come first.
- They contain the correct pairings, so every opening brace has a closing one.
- They are both of the same kind in a pair, so an opening parenthesis does not close with a closing curly brace.
For example, ()
is valid. ((
is not. Similarly, {{[]}}
is valid. [[}}
is not.
Constraints
- Length of the string <=
100000
- The string will only consist of characters like
[
,]
,{
,}
,(
,)
- Expected time complexity :
O(n)
- Expected space complexity :
O(n)
Try to solve this here or in Interactive Mode.
How do I practice this challenge?
xxxxxxxxxx
43
var assert = require('assert');
​
function validateSymbols(str) {
// implement this method
return str;
}
​
try {
assertIsFunction(validateSymbols);
​
console.log('PASSED: ' + '`validateSymbols` is a function');
} catch (err) {
console.log(err);
}
​
try {
assert.equal(validateSymbols('[]'), true);
​
console.log('PASSED: ' + "`validateSymbols('[]')` should return `true`");
} catch (err) {
console.log(err);
}
​
try {
assert.equal(validateSymbols('{{[]}}'), true);
​
console.log('PASSED: ' + "`validateSymbols('{{[]}}')` should return `true`");
} catch (err) {
console.log(err);
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment
Tired of reading? Watch this video explanation!
To change the speed of the video or see it in full screen, click the icons to the right of the progress bar.

Here's our guided, illustrated walk-through.
How do I use this guide?