FastPrepValid Parentheses
Problems/Valid Parentheses

Valid Parentheses

Zillow logoZillow● EasyFULLTIMEINTERNPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Asked at Zillow from about 2016 to 2025 in phone screens, onsite rounds and other coding interviews. The reports came from software intern candidates, senior software and senior data engineer candidates, one machine learning engineer candidate, and software candidates who gave no level. The task was to check whether the brackets in a string are matched and closed in the right order. Two reports called it a variant of the usual check without saying what changed, and one of those candidates also got follow-up questions.

The reports do not say which kinds of brackets appear, whether other characters can appear, or what the variant changed. Here the string holds only the three common bracket pairs, and you return true or false. The editorial covers two common follow-ups: strings with other characters, and strings with only one kind of bracket.

Our version is about 80% the same as the reported question.

Given a string s made only of the characters '(', ')', '[', ']', '{' and '}', return true if s is valid and false otherwise.

A string is valid when all of these hold:

  • Every opening bracket is closed by a closing bracket of the same kind.
  • Brackets close in the right order: a closing bracket must match the most recent opening bracket that is still open.
  • Every closing bracket has a matching opening bracket before it.

Function

isValid(s: String) → boolean

Examples

Example 1

s = "{[]()}"return = true

The pairs [] and () each close right away, and then } closes the { that holds them both.

Example 2

s = "[(])"return = false

When ] arrives, the most recent open bracket is (, not [, so the brackets close in the wrong order.

Example 3

s = "(()"return = false

The second ( is closed by ), but the first ( is never closed.

Example 4

s = "()]{}"return = false

After () closes, nothing is open, so the ] at index 2 has no opening bracket to match.

Constraints

  • 1 <= s.length <= 104
  • s consists only of the characters '(', ')', '[', ']', '{' and '}'.

More Zillow Phone Screen questions

  • Build a Hash TableOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Feb 2023
  • Reversible Run-Length EncodingPHONE SCREEN · Seen Nov 2022
  • First Unique Character in a StringOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2022
  • Cumulative Fibonacci SumOA · PHONE SCREEN · Seen Aug 2021
  • First N Fibonacci NumbersOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Jun 2021
  • Lowest Common Ancestor in a Binary TreePHONE SCREEN · Seen Sep 2019
  • LRU CachePHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2016
  • Blackjack Hand ScorePHONE SCREEN · ONSITE INTERVIEW · Seen Feb 2016
  • FactorialPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2014
  • Find the Four Missing Numbers in a FileOA · PHONE SCREEN · Seen Feb 2014

Similar questions at other companies

  • Valid ParenthesesByteDance · PHONE SCREENByteDance interview questions
  • Valid ParenthesesCisco · PHONE SCREENCisco interview questions
  • Valid ParenthesesMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Stack Formula InterpreterTypeSafe AI · PHONE SCREEN
  • Valid ParenthesesEPAM · ONSITE INTERVIEWEPAM interview questions
  • Valid ParenthesesQualys · ONSITE INTERVIEWQualys interview questions
  • Validate a Bracket SequenceTripAdvisor · PHONE SCREEN
  • Rich Text Parser Part 1 (Validate Tokens)Figma · PHONE SCREEN · ONSITE INTERVIEWFigma interview questions
  • Valid ParenthesesOracle · PHONE SCREENOracle interview questions
  • Valid ParenthesesAmazon · PHONE SCREEN · ONSITE INTERVIEW
All Zillow interview questionsSee Zillow hiring insights
Saved
class Solution {
    public boolean isValid(String s) {
        // Write your code here.
    }
}
Checking account…