File: root - text - article - 2020 - 02 - fix-brackets.txt
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Category: Computing | 1015 Views, 23503 Search Bots | 99 Words
| Browse | Archive
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Category: Computing | 1015 Views, 23503 Search Bots | 99 Words
| Browse | Archive
Hi, here's your problem today. This problem was recently asked by Twitter:
Given a string with only ( and ), find the minimum number of characters to add or subtract to fix the string such that the brackets are balanced.
Example:
Input: '(()()'
Output: 1
Explanation:
The fixed string could either be ()() by deleting the first bracket, or (()()) by adding a bracket. These are not the only ways of fixing the string, there are many other ways by adding it in different positions!
Here's some code to start with:
def fix_brackets(s):
# Fill this in.
print fix_brackets('(()()')
# 1
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Cateogry: Computing | 1015 Views, 23503 Search Bots | 99 Words Given a string with only ( and ), find the minimum number of characters to add or subtract to fix the string such that the brackets are balanced.
Example:
Input: '(()()'
Output: 1
Explanation:
The fixed string could either be ()() by deleting the first bracket, or (()()) by adding a bracket. These are not the only ways of fixing the string, there are many other ways by adding it in different positions!
Here's some code to start with:
def fix_brackets(s):
# Fill this in.
print fix_brackets('(()()')
# 1
Related Articles
- Daily Interview Problem: Find the k-th Largest Element in a List
- Daily Interview Puzzle: Minimum Size Subarray Sum
- Daily Interview Problem: Minimum Removals for Valid Parenthesis
- Algorithm Interview Question: Max and Min with Limited Comparisons
- [Daily Problem] Validate Balanced Parentheses
- Algorithm Interview: Convert Roman Numerals to Decimal
- Daily Interview Problem: Find the Number of Islands
- Daily Interview Problem: Jump to the End
- Linode Support Ticket 10029540 - Other - Important Notice Regarding Ubuntu 17.10 Image
- Daily Interview Problem: Reverse Words in a String
©2006~2024 SteakOverCooked - 0.00755 Seconds(s) - 2778.841 KB/s - 37 Online Memory: 493.92 KB
18:54:01 up 13 days, 18:33, 2 users, load average: 0.98, 0.86, 0.73 - Server PHP Version: 7.4.33
How to Cook a Perfect Steak? | <meta name="robots" content="index, follow">
18:54:01 up 13 days, 18:33, 2 users, load average: 0.98, 0.86, 0.73 - Server PHP Version: 7.4.33
Comments (0)
Read & Write - Normal - Mini - Post - All Comments - Statistics
Be the first one to comment this page !