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

Related Articles

  1. Daily Interview Problem: 3 Sum
  2. Sorting a list with 3 unique numbers
  3. Daily Interview Problem: Largest Product of 3 Elements I
  4. Algorithm Interview Question: Find the Single Element in an Array of Duplicates
  5. [Daily Problem] Add two numbers as a linked list
  6. Daily Interview Problem: Count Number of Unival Subtrees
  7. Daily Interview Problem: Deepest Node in a Binary Tree
  8. Daily Interview Puzzle: Falling Dominoes
  9. Algorithm Interview: Smallest Number that is not a Sum of a Subset of List
  10. How to Play WAV music under DOS?

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="noindex, follow" />