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
103 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
2k 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
58 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
112 views

(Leetcode) Valid parentheses

This is a Leetcode problem - Given a string containing just the characters '(', ')', '{', ...
4
votes
3answers
399 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
70 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
1answer
103 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
143 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
158 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
82 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
118 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
162 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
94 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
177 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
162 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
2k 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
70 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
436 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
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
534 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
358 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 ...
27
votes
6answers
49k 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
3k 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
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
394 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
309 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
1k 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
221 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
210 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
8k views

Valid Parenthesis

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

Reversing strings inside parentheses

How can I optimize this algorithm to reverse strings inside parentheses? ...
7
votes
1answer
2k 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
430 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
229 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
446 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
188 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
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
362 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
1k 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
3k 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 ...
2
votes
2answers
397 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
726 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
905 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
257 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. ...