[LeetCode] Minimum Deletions to Make Alternating Substring

3777. Minimum Deletions to Make Alternating Substring

You are given a string s of length n consisting only of the characters 'A' and 'B'.

You are also given a 2D integer array queries of length q, where each queries[i] is one of the following:

  • [1, j]: Flip the character at index j of s i.e. 'A' changes to 'B' (and vice versa). This operation mutates s and affects subsequent queries.
  • [2, l, r]: Compute the minimum number of character deletions required to make the substring s[l..r] alternating. This operation does not modify s; the length of s remains n.

A substring is alternating if no two adjacent characters are equal. A substring of length 1 is always alternating.

Return an integer array answer, where answer[i] is the result of the i^th query of type [2, l, r].

Read more
[LeetCode] Minimum Moves to Balance Circular Array

3776. Minimum Moves to Balance Circular Array

You are given a circular array balance of length n, where balance[i] is the net balance of person i.

In one move, a person can transfer exactly 1 unit of balance to either their left or right neighbor.

Return the minimum number of moves required so that every person has a non-negative balance. If it is impossible, return -1.

Note: You are guaranteed that at most 1 index has a negative balance initially.

Read more
[LeetCode] Minimum Number of Operations to Have Distinct Elements

3779. Minimum Number of Operations to Have Distinct Elements

You are given an integer array nums.

In one operation, you remove the first three elements of the current array. If there are fewer than three elements remaining, all remaining elements are removed.

Repeat this operation until the array is empty or contains no duplicate values.

Return an integer denoting the number of operations required.

Read more
[LeetCode] Reverse Words With Same Vowel Count

3775. Reverse Words With Same Vowel Count

You are given a string s consisting of lowercase English words, each separated by a single space.

Determine how many vowels appear in the first word. Then, reverse each following word that has the same vowel count. Leave all remaining words unchanged.

Return the resulting string.

Vowels are 'a', 'e', 'i', 'o', and 'u'.

Read more
[LeetCode] Last Remaining Integer After Alternating Deletion Operations

3782. Last Remaining Integer After Alternating Deletion Operations

You are given an integer n.

We write the integers from 1 to n in a sequence from left to right. Then, alternately apply the following two operations until only one integer remains, starting with operation 1:

  • Operation 1: Starting from the left, delete every second number.
  • Operation 2: Starting from the right, delete every second number.

Return the last remaining integer.

Read more
[LeetCode] Maximum Score After Binary Swaps

3781. Maximum Score After Binary Swaps

You are given an integer array nums of length n and a binary string s of the same length.

Initially, your score is 0. Each index i where s[i] = '1' contributes nums[i] to the score.

You may perform any number of operations (including zero). In one operation, you may choose an index i such that 0 <= i < n - 1, where s[i] = '0', and s[i + 1] = '1', and swap these two characters.

Return an integer denoting the maximum possible score you can achieve.

Read more
[LeetCode] Maximum Sum of Three Numbers Divisible by Three

3780. Maximum Sum of Three Numbers Divisible by Three

You are given an integer array nums.

Your task is to choose exactly three integers from nums such that their sum is divisible by three.

Return the maximum possible sum of such a triplet. If no such triplet exists, return 0.

Read more
[LeetCode] Mirror Distance of an Integer

3783. Mirror Distance of an Integer

You are given an integer n.

Define its mirror distance as: abs(n - reverse(n))​​​​​​​ where reverse(n) is the integer formed by reversing the digits of n.

Return an integer denoting the mirror distance of n​​​​​​​.

abs(x) denotes the absolute value of x.

Read more
[LeetCode] Maximum Score of a Split

3788. Maximum Score of a Split

You are given an integer array nums of length n.

Choose an index i such that 0 <= i < n - 1.

For a chosen split index i:

  • Let prefixSum(i) be the sum of nums[0] + nums[1] + ... + nums[i].
  • Let suffixMin(i) be the minimum value among nums[i + 1], nums[i + 2], ..., nums[n - 1].

The score of a split at index i is defined as:

score(i) = prefixSum(i) - suffixMin(i)

Return an integer denoting the maximum score over all valid split indices.

Read more
[LeetCode] Minimum Deletion Cost to Make All Characters Equal

3784. Minimum Deletion Cost to Make All Characters Equal

You are given a string s of length n and an integer array cost of the same length, where cost[i] is the cost to delete the i^th character of s.

You may delete any number of characters from s (possibly none), such that the resulting string is non-empty and consists of equal characters.

Return an integer denoting the minimum total deletion cost required.

Read more