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

Related Articles

  1. Skip the readings, focus on problems. And use all the hints!
  2. Consecutive Ones
  3. New Vulnerabilities (CVE-2016-4581) have been detected in CentOS/RHEL/CloudLinux 7
  4. Daily Interview Problem: Reverse Integer
  5. PHP Unit Tests on VPS Server
  6. Daily Interview Problem: Word Ordering in a Different Alphabetical Order
  7. Algorithm Interview: Maximum Path Sum in Binary Tree
  8. Daily Interview Problem: Jump to the End
  9. Daily Interview Puzzle: Ways to Traverse a Grid
  10. Algorithm Interview: Lowest Common Ancestor of 2 Nodes in Binary Tree

Comments (0)

    Be the first one to comment this page !


Page Edited: May 11 2024 14:36:49 | RSS Subscription
How to Cook a Perfect Steak? | <meta name="robots" content="index, follow">