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
5
votes
2answers
365 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 ...
3
votes
0answers
62 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 ...
4
votes
2answers
110 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 ...
8
votes
1answer
94 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
2answers
696 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 ...
9
votes
2answers
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 ...
3
votes
1answer
74 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
2answers
739 views

(Leetcode) Valid parentheses

This is a Leetcode problem - Given a string containing just the characters '(', ')', '{', ...
4
votes
3answers
460 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 ...
4
votes
1answer
1k 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: ...
1
vote
2answers
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 ...
6
votes
1answer
2k 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: ...
4
votes
1answer
163 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
186 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
377 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
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). ...
2
votes
2answers
440 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
617 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
335 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
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 ...
3
votes
0answers
145 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
637 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
3k views

Check if brackets are balanced

...
3
votes
1answer
2k 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
825 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
4k views

Check if a string contains matching brackets

Trying to solve a case for a set of multiple types of brackets. ...
3
votes
1answer
426 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
6answers
68k 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
3answers
7k 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
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
4answers
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 ...
9
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
474 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
365 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
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 ...
2
votes
3answers
269 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
266 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
10k views

Valid Parenthesis

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

Reversing strings inside parentheses

How can I optimize this algorithm to reverse strings inside parentheses? ...
7
votes
1answer
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 ...
3
votes
2answers
518 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
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: ...
5
votes
1answer
458 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
536 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
221 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....
8
votes
4answers
5k 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
473 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 ...
3
votes
3answers
2k 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 ...
6
votes
5answers
7k 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 ...