Finally-- if at any time, we encounter a mismatch, we know it's an invalid string.
The time complexity is O(n), as we iterate through all the characters of the string.
xxxxxxxxxx43
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`");OUTPUT
Results will appear here.