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.

Filter by
Sorted by
Tagged with
2 votes
3 answers
464 views

Check if parentheses are balanced using a stack implemented with a linked list

Problem: Stacks can be used to check whether the given expression has balanced symbols. This algorithm is very useful in compilers. Each time the parser reads one character at a time. If the character ...
  • 29
2 votes
1 answer
78 views

Leetcode problem: minimum removal to make valid parentheses

I was working on this problem on leetcode Question Your task is to remove the minimum number of parentheses ( '(' or ')', in any positions ) so that the resulting parentheses string is valid and ...
  • 179
2 votes
1 answer
58 views

follow-up - Checking Nested Bracket Levels in Strings Programming Challenge

A follow-up to this question, this post improves on test case issues. To restate problem parameters, a given string S is considered closed if it: Has a matching ...
  • 2,927
3 votes
2 answers
177 views

Programming Challenge - Capturing Bracket Levels

I don't have a formal description for this problem, but here are the parameters: Given a string S check that each opening bracket has a matching closing bracket. ...
  • 2,927
8 votes
1 answer
1k views

Check for balanced brackets in JavaScript

Rules: You should create a function that receives a string with brackets, parentheses, or curly brackets, an example: test('{A}') The function must check that the ...
5 votes
2 answers
2k views

C# code to check balanced brackets in a string

The code works, at least against the unit tests. But I would like input on how to refactor it. Or also maybe a way to do this without using temporary lists? I also have some special checks, like if ...
  • 63
3 votes
1 answer
210 views

Generate valid combinations of parentheses

Playing on leetcode coding problem: "Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses." I realized that my understanding of Python was ...
  • 273
4 votes
2 answers
138 views

Retrieving top-level opening and closing sequences from a Python string

The problem I'm solving is a more complex version of pairing up opening and closing brackets. Instead of matching only on ([{}]), I additionally need to match ...
  • 198
8 votes
1 answer
102 views

Parenthesis-realigning program

This is my code for an assignment. The task is to take a user input in form of a sequence of parenthesis' followed by an E to mark its end and determine whether it is a correct sequence (as an example ...
5 votes
2 answers
773 views

Bracket balance checker in Python

Implement a feature for a text editor to find errors in the usage of brackets in the code. Input: sorted(list(zip(a, b)) Output: False Input: ([{}, {}]) Output: True Here's my implementation in ...
's user avatar
9 votes
2 answers
4k views

Balanced parentheses using standard C++

Here is a small program for checking if the parentheses are balanced or not. I am new to the standard library, and this is my first program. How can I improve it? Any kind of modifications or ...
  • 291
3 votes
1 answer
90 views

CareerCup (Bloomberg): Check if string is valid based on brackets

The goal of this problem is to determine if a string with brackets is valid. Below is a summary of the question from careercup. Check if string s is valid based on brackets ...
0 votes
2 answers
1k views

(Leetcode) Valid parentheses

This is a Leetcode problem - Given a string containing just the characters '(', ')', '{', ...
  • 2,458
4 votes
3 answers
494 views

Generate parentheses solution

I have coded a solution to build all valid permutations of parentheses. My code is below. I have a question on my code based on a comment by my PEP8 checker. It said that there was no need to ...
  • 2,033
4 votes
1 answer
2k views

Generate all possible combination of n-pair parentheses

The task is taken from LeetCode Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is: ...
  • 3,953
1 vote
1 answer
2k views

Python program to remove invalid parentheses

This is a Leetcode problem - Remove the minimum number of invalid parentheses in order to make the input string valid. Return all possible results. Note - The input string may contain ...
  • 2,458
7 votes
1 answer
3k views

Given a string containing just parentheses, determine if the input string is valid

The task is taken from leetcode Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. An input string is valid if: ...
  • 3,953
4 votes
1 answer
167 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 ...
  • 175
1 vote
1 answer
223 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, ...
  • 3,953
4 votes
2 answers
781 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 ...
  • 3,953
1 vote
2 answers
2k 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). ...
  • 3,953
2 votes
2 answers
3k 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,469
2 votes
2 answers
721 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 ...
  • 305
1 vote
2 answers
394 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 ...
  • 35
6 votes
2 answers
4k 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 ...
  • 171
3 votes
0 answers
167 views

Removing text inside brackets [closed]

The following function removes text inside parenthesis, also checks for balanced brackets. Example: RemoveTextInsideParenthesis('Yahoo (Inc)') will return ...
  • 601
3 votes
0 answers
708 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
2 answers
3k views

Check if brackets are balanced

...
  • 217
3 votes
1 answer
3k 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. ...
  • 5,331
2 votes
1 answer
916 views

Longest Valid Parentheses

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

Check if a string contains matching brackets

Trying to solve a case for a set of multiple types of brackets. ...
  • 193
3 votes
1 answer
472 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 ...
30 votes
6 answers
70k 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: (, ...
4 votes
3 answers
9k 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,067
5 votes
5 answers
2k 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
4 answers
4k 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 ...
  • 257
9 votes
2 answers
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
1 answer
521 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
2 answers
2k 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 ...
  • 311
3 votes
2 answers
382 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 ...
  • 303
4 votes
2 answers
3k 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
3 answers
296 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 ...
  • 123
5 votes
1 answer
342 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
1 answer
10k views

Valid Parenthesis

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

Reversing strings inside parentheses

How can I optimize this algorithm to reverse strings inside parentheses? ...
7 votes
1 answer
3k 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 ...
  • 303
3 votes
2 answers
581 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,443
3 votes
2 answers
2k 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: ...
  • 1,066
5 votes
1 answer
593 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 ...
  • 3,443
2 votes
2 answers
599 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 ...
  • 3,443