Skip to main content
All Questions

Valid Parentheses

Easy

Given a string s containing just the characters '(', ')', '{', '}', '[', and ']', write a function isValid to determine if the input string is valid. An input string is valid if:

  1. Open brackets must be closed by the same type of brackets.
  2. Open brackets must be closed in the correct order.

Return true if the string is valid, otherwise return false.

Examples

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

In the first example, all brackets are properly closed and nested, so the result is false. In the second example, each type of bracket is matched and nested correctly, so the result is also true.

Constraints

  • The string s has a length of at most 10^4.

Interview experiences

5 shared
Roblox · 3 months ago
"Fairly standard interview process, recruiters are very helpful in giving general direction of how to prepare for each interview"
Software Engineer · Senior / L5
MongoDB · 5 months ago
"I think I did pretty decently overall, though I felt there was definitely room for improvement. The technical questions were very appropriate for an Entry Level SWE role, and you could arrive at coherent answers by practicing the 150 Neetcode questions, and using proper application from DSA classes. Though the hiring manager interview at the end was stranger, as it focused more on just general problem solving / knowledge questions as opposed to a full-on behavioural. The behavioural questions I felt I could've done better, mostly because I was unprepared for it and should have spent more time making my responses more coherent."
Software Engineer · Entry Level / L3
Amazon · 2 years ago
"There is not that much interaction with a recruiter. I was lucky in the coding question was not hard but they have a bank essentially similar to leetcode mediums. The bar raiser round you should prepare stories for each one"
Software Engineer · Mid Level / L4
Bloomberg · 2 years ago
"1 Phone Leetcode Onsite loop 1 LC, 1 SD, 1HR + 1 EM ( 30m each) Process seemed quite standard, the leetcode were all from top 50 tagged."
Software Engineer
Amazon · 2 years ago
"Recruiter was super helpful throughout the process helping me navigate through the process and super responsive whenever I had any questions. Lot of interesting questions asked to test problem solving + LPs related questions can sometimes put you on spot in revealing things that you don't want to. Overall it was a good experience and recruiter reached out to me after a week."
QA Engineer · Mid Level / L4

Related courses

Course

Machine Learning Engineer Interview Prep

Land your dream machine learning role at Meta, Google, Amazon, Apple, Microsoft, Nvidia, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates. Explore ML system design, core concepts, coding, behavioral interviews, and more.

Course

Data Science Interview Prep

Land your dream data science role at Google, Amazon, Microsoft, Meta, Apple, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates. Practice statistics, experimentation, coding, SQL, machine learning, behavioral interviews, and more.