FastPrepValid Parentheses
Problems/Valid Parentheses

Valid Parentheses

Kotak Mahindra Bank logoKotak Mahindra Bank● EasyFULLTIMEONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The source report identifies the linked Valid Parentheses task. The callable signature, examples, and execution bounds reuse the equivalent reviewed FastPrep task; estimated source fidelity is 95%.

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

A string is valid when every opening bracket is closed by the same type of bracket and brackets close in the reverse order in which they were opened. The empty string is valid.

Return true if s is valid; otherwise, return false.

Function

isValidParentheses(s: String) → boolean

Examples

Example 1

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

Each opening bracket is immediately followed by its matching closing bracket.

Example 2

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

The brackets are properly nested and close in reverse opening order.

Example 3

s = "([)]"return = false

The closing parenthesis appears before the nested square bracket is closed.

Constraints

  • 0 <= s.length <= 100000.
  • Every character of s is one of ()[]{}.

More Kotak Mahindra Bank problems

  • Best Time to Buy and Sell StockONSITE INTERVIEW · Seen Nov 2026
  • Best Time to Buy and Sell Stock IIONSITE INTERVIEW · Seen Nov 2026
  • Maximum Non-Adjacent Coins in Two RowsONSITE INTERVIEW · Seen Oct 2026
All Kotak Mahindra Bank interview questionsSee Kotak Mahindra Bank hiring insights
Saved
class Solution {
    public boolean isValidParentheses(String s) {
        // write your code here
    }
}
Checking account…