All Posts
Leetcode 1712: Ways to Split Array Into Three Subarrays
You are given an array of non-negative integers. Your task is to count the number of ways the array can be split into three contiguous non-empty subarrays: left, mid, and right. The sum of the elements in the left subarray should be less than or equal to the sum in the mid subarray, and the sum of the mid subarray should be less than or equal to the sum of the right subarray. Return the number of such good splits modulo 10^9 + 7.
Leetcode 1717: Maximum Score From Removing Substrings
You are given a string s
and two integers x
and y
. You can perform two types of operations any number of times:
- Remove the substring “ab” and gain
x
points. - Remove the substring “ba” and gain
y
points.
Each time a substring is removed, the characters are deleted from the string, and the corresponding points are added to your total score. Your task is to maximize the total score after applying these operations any number of times.
Leetcode 1718: Construct the Lexicographically Largest Valid Sequence
Given an integer n
, find a sequence of length 2n - 1
that satisfies the following conditions:
- The integer
1
occurs once in the sequence. - Each integer between
2
andn
occurs twice in the sequence. - For every integer
i
between2
andn
, the distance between the two occurrences ofi
is exactlyi
. - The sequence should be lexicographically the largest possible sequence.
The sequence is considered lexicographically larger if, at the first position where the two sequences differ, the number in the first sequence is greater.