Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [balanced-delimiters]

When delimiters (a character or sequence marking the beginning, end, or boundary of a unit of data) are correctly placed (often in pairs) within a sequence or sequences of data.

4
votes
1answer
133 views

Return all valid paren strings with a given length

The problem is Given a non-negative integer n, return all valid parentheses strings with n open parens and ...
1
vote
1answer
52 views

Check whether string of brackets are well-formed

The task I asked similar questions here and here. Given a string of round, curly, and square open and closing brackets, return whether the brackets are balanced (well-formed). For example, ...
4
votes
2answers
86 views

Check whether string of braces, brackets, and parentheses is balanced

The Task is taken from codewars: Write a function that takes a string of braces, and determines if the order of the braces is valid. It should return true if ...
1
vote
2answers
69 views

Minimum number of parentheses to be removed to make a string of parentheses balanced

The task: Given a string of parentheses, write a function to compute the minimum number of parentheses to be removed to make the string valid (i.e. each open parenthesis is eventually closed). ...
1
vote
2answers
80 views

Bracket matcher in Python

I would like to receive feedback on my coding interview for the following problem: Bracket Match A string of brackets is considered correctly matched if every opening bracket in the string ...
2
votes
2answers
120 views

Using the stack algorithm for parenthesis matching

I have used Stacks to check for brackets mismatch. (Parentheses matching problem using Stack algorithm) Any suggestions on how to improve the code? I have tried various examples and it works ...
1
vote
2answers
119 views

Balanced parenthesis, with backslash escaping

Given a Balanced Parenthesis problem. "Balanced Parenthesis Create a program that checks if in a given string expression all the parenthesis are balanced. For Example: (test) - valid ...
6
votes
2answers
1k views

Looping through a string finding nested brackets

So I've been trying to check through a string, looping for, [ (start) and ] (end). In this, I also have to check for nested ...
3
votes
0answers
57 views

Removing text inside brackets [closed]

The following function removes text inside parenthesis, also checks for balanced brackets. Example: RemoveTextInsideParenthesis('Yahoo (Inc)') will return ...
3
votes
0answers
350 views

Find redundant braces in an input string

I am solving interview questions from here. Problem : Write a program to validate if the input string has redundant braces Return 0/1 : ...
4
votes
2answers
2k views

Check if brackets are balanced

...
3
votes
1answer
1k views

Stacks: Balanced Brackets Hacker Rank

Here is the general goal of this exercise: For each string, print whether or not the string of brackets is balanced on a new line. If the brackets are balanced, print YES; otherwise, print NO. ...
2
votes
1answer
378 views

Longest Valid Parentheses

This is the "Longest Valid Parentheses" problem from leetcode.com: Given a string containing just the characters "(" and ")", ...
3
votes
3answers
2k views

Check if a string contains matching brackets

Trying to solve a case for a set of multiple types of brackets. ...
3
votes
1answer
314 views

Check balanced brackets in a text

Given an input text that is a combination of {, }, [, ], (, ) characters, check whether the input text has balanced brackets or not. This was a question from hackerrank, and the code below solves it ...
23
votes
7answers
39k views

Checking for balanced brackets in Python

I'm solving HackerRank "Stacks: Balanced Brackets" in Python. A bracket is considered to be any one of the following characters: (, ...
3
votes
3answers
2k views

Find the corresponding closing parenthesis

Problem: "Sometimes (when I nest them (my parentheticals) too much (like this (and this))) they get confusing." Write a function that, given a sentence like the one above, along with the ...
5
votes
5answers
1k views

LeetCode parentheses matching

I came across this question from LeetCode OJ where I am given a string containing parentheses and I need to find out if the string contains valid matching parentheses or not. Given a string ...
9
votes
4answers
3k views

Checking for parentheses balance in C

A recent assignment asks me to create a program that checks for parentheses balance in a given string. As I can't find any duplicate questions that have code written in C, I decided to post another ...
10
votes
2answers
2k views

A counterexample in balanced parentheses

In this program I had to analyse if the parenthesis given are well balanced. For instance, input (()) is correct and input ())(()...
1
vote
1answer
367 views

Analyzing an arithmetic expression using stacks

I'm looking for some constructive (harsh) criticism of a homework I've done (the code works fine). Also Is there a better/another way to solve the exercise? Exercise: Read an arithmetic expression ...
5
votes
2answers
1k views

Balancing parentheses (),{},[] routine

I have written a simple routine to check if the number of parentheses balances, so [{}] would return true since all parentheses which are opened are closed in the ...
3
votes
2answers
284 views

Valid Parentheses Algorithm Effeciency

What do you think of my Algorithm? I start to eliminate the nearest valid parentheses and if string.length == 0 so it's valid ...
4
votes
2answers
831 views

isBalanced function for checking if string with brackets is balanced ([{}])

I wrote simple function for checking if string is balanced (with brackets ([{}])). It takes a string argument and need to return boolean value (true if string is ...
2
votes
3answers
194 views

Loop for finding proper grouping brackets

I've got this piece of code that you pass a string of special characters to and an index which points to a location in this string. The code will take the index, analyze the string, and return a new ...
5
votes
1answer
186 views

Print combinations of balanced parentheses

Solved the below problem. Would love to hear your feedback, especially on performance improvements (granted, the solution should remain recursive). Especially concerned about the ...
6
votes
1answer
7k views

Valid Parenthesis

Recently, I've solved the "Valid Parenthesis" problem on LeetCode: Given a string containing just the characters '(', ')', <...
2
votes
1answer
3k views

Reversing strings inside parentheses

How can I optimize this algorithm to reverse strings inside parentheses? ...
7
votes
1answer
1k views

Check for valid parentheses nesting

I found this question on leetcode and that was my answer ... But someone told me it's too bad that it takes \$O(n^3)\$ I am not sure that it takes all that time ... and trying to find better ...
3
votes
2answers
404 views

Balanced smileys check algorithm (part 4)

This is a follow-up for here, for bug fixes and applied advice. Problem Your friend John uses a lot of emoticons when you talk to him on Messenger. In addition to being a person who likes to ...
3
votes
2answers
1k views

Matching parentheses

I have a string that contains a random order of parenthesis {[()]}. I want to check if for any given parenthesis is there a matching closing one. Example: ...
5
votes
1answer
199 views

Balanced smileys check algorithm (part 3)

This is a follow-up for here, for bug fixes and applied advice. Problem Your friend John uses a lot of emoticons when you talk to him on Messenger. In addition to being a person who likes to ...
2
votes
2answers
418 views

Balanced smileys check algorithm (part 2)

This is a follow-up for here. Problem Your friend John uses a lot of emoticons when you talk to him on Messenger. In addition to being a person who likes to express himself through ...
4
votes
2answers
174 views

Matched Brackets challenge

I am attempting the matched brackets problem. I have written a Python program which seems to do the job but is very slow and thus exceeds the time limit. Please help me making this code more efficient....
7
votes
4answers
4k views

Balanced Parentheses checker in Python

I'd appreciate feedback on the code itself (style, performance optimization (both space and time)), and also on the algorithm (because I think this is typically implemented using a stack). The ...
2
votes
1answer
328 views

Balanced smileys check algorithm

Problem Your friend John uses a lot of emoticons when you talk to him on Messenger. In addition to being a person who likes to express himself through emoticons, he hates unbalanced ...
4
votes
3answers
962 views

Check if all of the delimiters in an expression are matched and closed

Problem Write an algorithm to determine if all of the delimiters in an expression are matched and closed. {(abc)22}[14(xyz)2] should pass ...
3
votes
5answers
2k views

Validate that brackets are balanced

I've done a test for a job (which I failed) and I'd like to know in which ways my code could've been better. Here are the questions and my answers, it's not very long. 1) Make a program that ...
3
votes
2answers
369 views

Check syntax (string and character comparison)

I would like to know if my function that checks if a string syntax is correct. It's currently very messy, but seems to do the job. ...
1
vote
1answer
682 views

Check for balanced parentheses in JavaScript

I just implemented the balanced parentheses problem in JavaScript. For those of you who are new to this problem, a statement of it would be: Give a string of parentheses (including braces and ...
5
votes
2answers
894 views

Checking the balanced parenthesis as asked in interview

Input: Input contains one string S which consists of big and small latin letters, digits, punctuation marks and brackets from the set []{}(). Constraint: Constraints. The length of S ...
3
votes
3answers
237 views

Checking if parentheses are balanced

This script checks if parentheses are balanced. I wonder if there is something that can be improved here including ES6 features. ...
6
votes
1answer
207 views

Balancing Brackets Algorithm: Stack Data Structure

I am currently refining my understanding of data structures and as such, decided to implement a popular application of the Stack. Below you will find my implementation of the Balancing Symbols ...
4
votes
1answer
3k views

Swift HackerRank Balanced Brackets

I solved this stack problem in Swift. Looking for any feedback on my code: ...
4
votes
2answers
3k views

Balanced parenthesis in Ruby

I'm solving the "Balanced Parenthesis" problem in Ruby, and I came up with this solution. ...
0
votes
1answer
78 views

Balanced parenthesis string checker

Please review my balanced parenthesis string checker code below. I would love to know how to improve my algorithm and if you have any other feedback. ...
5
votes
1answer
2k views

Matching parenthesis

This is a simple implementation of a parenthesis-matcher. Given an expression, I want to find out if it is balanced.For example, the expression '{{[[()]]}}' is balanced while '{]{{}}]]' is not. I will ...
7
votes
4answers
2k views

Balanced braces

I wanted to write a JavaScript function that checked for balanced braces. I'd be grateful for any feedback on correctness and style. ...
6
votes
3answers
7k views

Checking balanced parenthesis string

I recently wrote a code in online recruitment test. It was very good. With each question, there were associated space and time limits check. If our code executed correctly within both limits, only ...
4
votes
1answer
367 views

All balanced parentheses for a given N

Write a function (in Haskell) which makes a list of strings representing all of the ways you can balance N pairs of parentheses: Example: ...