To the Top
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 | 678 Views, 18694 Search Bots | 99 Words

Subscribe to Feed Burner | 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 | 678 Views, 18694 Search Bots | 99 Words Subscribe to Feed Burner

Related Articles

  1. Daily Interview Problem: Given two arrays, write a function to compute their intersection.
  2. ImageMagick Vulnerabilities -  CVE-2016–3714
  3. Two Tricks of Delphi
  4. New Vulnerabilities (CVE-2016-4581) have been detected in CentOS/RHEL/CloudLinux 7
  5. Daily Interview Problem: Merge List Of Number Into Ranges
  6. Daily Interview Problem: Longest Substring With K Distinct Characters
  7. Sorting a list with 3 unique numbers
  8. Daily Interview Problem: Find the Number of Islands
  9. Daily Interview Problem: Min Range Needed to Sort
  10. Algorithm Interview: Convert Roman Numerals to Decimal

Comments (0)

Your Email (Domain Part Not Exposed):

Your Comments:

Privately By Mail Colors More Smileys S x y @

Verification (Click Image 2 Refresh):

    Be the first one to comment this page !


Page Edited: October 30 2020 14:21:09 | RSS Subscription
How to Cook a Perfect Steak? | <meta name="robots" content="noindex, follow" />