Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.

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
1 answer
61 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 ...
user avatar
  • 179
2 votes
1 answer
49 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 ...
user avatar
  • 2,897
3 votes
2 answers
166 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. ...
user avatar
  • 2,897
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 ...
user avatar
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 ...
user avatar
  • 63
3 votes
1 answer
133 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 ...
user avatar
  • 273
4 votes
2 answers
128 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 ...
user avatar
8 votes
1 answer
99 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 ...
user avatar
5 votes
2 answers
761 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 ...
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 ...
user avatar
  • 291
3 votes
1 answer
85 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 ...
user avatar
0 votes
2 answers
968 views

(Leetcode) Valid parentheses

This is a Leetcode problem - Given a string containing just the characters '(', ')', '{', ...
user avatar
  • 2,460
4 votes
3 answers
483 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 ...
user avatar
  • 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: ...
user avatar
  • 3,955
1 vote
1 answer
1k 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 ...
user avatar
  • 2,460
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: ...
user avatar
  • 3,955
4 votes
1 answer
165 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 ...
user avatar
  • 175
1 vote
1 answer
207 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, ...
user avatar
  • 3,955
4 votes
2 answers
648 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 ...
user avatar
  • 3,955
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). ...
user avatar
  • 3,955
2 votes
2 answers
597 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 ...
user avatar
  • 2,469
2 votes
2 answers
696 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 ...
user avatar
  • 305
1 vote
2 answers
369 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 ...
user avatar
  • 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 ...
user avatar
  • 171
3 votes
0 answers
162 views

Removing text inside brackets [closed]

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

Check if brackets are balanced

...
user avatar
  • 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. ...
user avatar
  • 5,249
2 votes
1 answer
887 views

Longest Valid Parentheses

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

Check if a string contains matching brackets

Trying to solve a case for a set of multiple types of brackets. ...
user avatar
  • 193
3 votes
1 answer
461 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 ...
user avatar
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: (, ...
user avatar
4 votes
3 answers
8k 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 ...
user avatar
  • 5,017
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 ...
user avatar
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 ...
user avatar
  • 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 ())(()...
user avatar
1 vote
1 answer
504 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 ...
user avatar
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 ...
user avatar
  • 311
3 votes
2 answers
372 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 ...
user avatar
  • 303
4 votes
2 answers
2k 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 ...
user avatar
2 votes
3 answers
284 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 ...
user avatar
  • 123
5 votes
1 answer
295 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 ...
user avatar
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 '(', ')', <...
user avatar
  • 17k
2 votes
1 answer
6k views

Reversing strings inside parentheses

How can I optimize this algorithm to reverse strings inside parentheses? ...
user avatar
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 ...
user avatar
  • 303
3 votes
2 answers
570 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 ...
user avatar
  • 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: ...
user avatar
  • 1,066
5 votes
1 answer
552 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 ...
user avatar
  • 3,443
2 votes
2 answers
581 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 ...
user avatar
  • 3,443
4 votes
2 answers
241 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....
user avatar
  • 153