Practice Real Company Assessment Patterns • Latest 2025–2026 Mock Tests

Programming Exercises

Implement a function to check if a given string contains balanced parentheses.

Hard

Problem Statement

Implement a function to check if a given string contains balanced parentheses.

Sample Input

A hardcoded string, e.g., "(a + b) * (c - d)".

Sample Output

The string has balanced parentheses

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
fun isBalanced(input: String): Boolean { // Add your code here to check for balanced parentheses } fun main() { val input = "(a + b) * (c - d)" if (isBalanced(input)) { println("The string has balanced parentheses") } else { println("The string does not have balanced parentheses") } }
Log in or sign up to run or submit your code.Log inSign up
Input
A hardcoded string, e.g., "(a + b) * (c - d)".
Expected Output
The string has balanced parentheses