[LeetCode] Minimum Insertions to Balance a Parentheses String

1541. Minimum Insertions to Balance a Parentheses String

Given a parentheses string s containing only the characters ‘(‘ and ‘)’. A parentheses string is balanced if:

  • Any left parenthesis ‘(‘ must have a corresponding two consecutive right parenthesis ‘))’.
  • Left parenthesis ‘(‘ must go before the corresponding two consecutive right parenthesis ‘))’.

In other words, we treat ‘(‘ as an opening parenthesis and ‘))’ as a closing parenthesis.

  • For example, “())”, “())(())))” and “(())())))” are balanced, “)()”, “()))” and “(()))” are not balanced.

You can insert the characters ‘(‘ and ‘)’ at any position of the string to balance it if needed.

Return the minimum number of insertions needed to make s balanced.

Read more
[LeetCode] Bulb Switcher

319. Bulb Switcher

There are n bulbs that are initially off. You first turn on all the bulbs, then you turn off every second bulb.

On the third round, you toggle every third bulb (turning on if it’s off or turning off if it’s on). For the ith round, you toggle every i bulb. For the nth round, you only toggle the last bulb.

Return the number of bulbs that are on after n rounds.

Read more
[LeetCode] Minimum Moves to Equal Array Elements II

462. Minimum Moves to Equal Array Elements II

Given an integer array nums of size n, return the minimum number of moves required to make all array elements equal.

In one move, you can increment or decrement an element of the array by 1.

Test cases are designed so that the answer will fit in a 32-bit integer.

Read more
[LeetCode] Maximum Number of Non-Overlapping Subarrays With Sum Equals Target

1546. Maximum Number of Non-Overlapping Subarrays With Sum Equals Target

Given an array nums and an integer target, return the maximum number of non-empty non-overlapping subarrays such that the sum of values in each subarray is equal to target.

Read more
[AtCoder] C - ShapesRead more
[AtCoder] E - DestructionRead more
[AtCoder] D - RectanglesRead more
[AtCoder] B - Cross-free MatchingRead more
[AtCoder] A - Make 10Read more
[Codeforces] Round #574 (Div. 2) C. Basketball ExerciseRead more