Sitemap
JavaScript in Plain English

New JavaScript and Web Development content every day. Follow to join our 3.5M+ monthly readers.

Day 27 — Daily JavaScript Algorithm

Valid Parentheses Checker

3 min readMar 3, 2025

--

Press enter or click to view image in full size

Welcome to Day 27 of our Daily JavaScript Algorithm series! Today, we’ll solve the Valid Parentheses problem, an essential question in stack-based algorithms and coding interviews.

Not a Member? Read for FREE here.

Problem Statement

Given a string s containing only the characters (, ), {, }, [ and ], determine if the input string is valid.

A string is valid if:

  1. Open brackets are closed by the same type of brackets.
  2. Open brackets are closed in the correct order.
  3. Every close bracket has a corresponding open bracket of the same type.

Example 1:

  • Input: s = "()"
  • Output: true

Example 2:

  • Input: s = "()[]{}"
  • Output: true

Example 3:

  • Input: s = "(]"
  • Output: false

Example 4:

  • Input: s = "{[()]}"
  • Output: true

Example 5:

  • Input: s = "{[(])}"

--

--

Dipak Ahirav
Dipak Ahirav

Written by Dipak Ahirav

AI & Full-Stack Engineer | Technical Writer. Sharing practical insights on Angular, JavaScript, AI systems, and scalable software architecture.

JavaScript in Plain English
JavaScript in Plain English

Published in JavaScript in Plain English

New JavaScript and Web Development content every day. Follow to join our 3.5M+ monthly readers.