Check if a string of parentheses is balanced.

This function takes in a string consisting only of parentheses and outputs whether or not the string is balanced. A string is balanced if every open parenthesis has a corresponding close parenthesis and there are no unmatched parentheses.

Problem

Given a string containing only parentheses, write a function to determine whether the string is balanced. A string is balanced if every open parenthesis has a corresponding close parenthesis and the string does not contain any unmatched parentheses.
Examples:
Input: "()"
Output: True
Input: "(())"
Output: True
Input: "()()"
Output: True
Input: "(())"
Output: True
Input: ")("
Output: False

Solution

This solution is in C#. Our A.I. can create solutions in multiple languages.
by kayakane
using System;
using System.Collections.Generic;

namespace InterviewPreperationGuide.Core.CrackingTheCodingInterview.c3q5 {
    public class Solution {
        public void Init () {
            Console.WriteLine ();
        }
    }
}

A.I. Evaluation of the Solution

The candidate's solution does not demonstrate a level of completeness and does not solve the problem. The general approach is not clear.

Evaluated at: 2022-12-10 04:15:29