Implement a function to check if a given string contains balanced parentheses.
HardProblem 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")
}
}
Input
A hardcoded string, e.g., "(a + b) * (c - d)".
Expected Output
The string has balanced parentheses