3986. Number of Elapsed Seconds Between Two Times
You are given two valid times
startTimeandendTime, each represented as a string in the format"HH:MM:SS".Return the number of seconds that have elapsed from
startTimetoendTime.
3986. Number of Elapsed Seconds Between Two Times
You are given two valid times
startTimeandendTime, each represented as a string in the format"HH:MM:SS".Return the number of seconds that have elapsed from
startTimetoendTime.
3987. Minimum Total Cost to Process All Elements
You are given an integer array
numsand an integerk.Initially, you have
kunits of resources.You must process the elements of
numsfrom left to right. To process thei^thelement, you neednums[i]resources.If your available resources are less than
nums[i], you may perform an operation that increases your available resources byk. The value ofkis fixed and does not change throughout the process. The first such operation incurs a cost of 1, the second incurs a cost of 2, and so on.After processing the
i^thelement, your available resources decrease bynums[i].Return an integer denoting the minimum total cost required to process all elements. Since the answer may be very large, return it modulo
10^9 + 7.
3988. Create Grid With Exactly K Paths I
You are given three integers
m,n, andk.Construct any
m x ngrid consisting only of the characters'.'and'#', where:
'.'represents a free cell.'#'represents an obstacle cell.A valid path is a sequence of free cells that:
- Starts at the top-left cell
(0, 0).- Ends at the bottom-right cell
(m - 1, n - 1).- Moves only:
- Right, from
(i, j)to(i, j + 1), or- Down, from
(i, j)to(i + 1, j).Return any grid such that there are exactly
kvalid paths from the top-left cell to the bottom-right cell. If no such grid exists, return an empty array.
3989. Maximum Consistent Columns in a Grid
You are given a 2D integer array
gridof sizem x n, and an integerlimit.You may remove zero or more columns from the grid, but at least one column must remain. The relative order of the remaining columns must be preserved.
A grid is called consistent if for every row
i, and for every pair of adjacent remaining columnsaandbwitha < b, the following holds:|grid[i][b] - grid[i][a]| <= limit.Return the maximum number of columns that can remain such that the resulting grid is consistent.
3991. Sort Array Using Prefix Reversals
You are given an integer array
numsof lengthn, wherenumsis a permutation of the integers in the range[0, n - 1].You are also given an integer array
pre, where eachpre[i]is a valid prefix length.In one operation, you may choose any length
xfrompreand reverse the firstxelements ofnums.For example, applying a prefix reversal of length
3on[4, 1, 2, 3]results in[2, 1, 4, 3].Return the minimum number of operations required to sort
numsin ascending order. If it is impossible to sortnums, return-1.
3992. Rearrange String to Avoid Character Pair
You are given a string
sand two distinct lowercase English lettersxandy.Rearrange the characters of
sto construct a new stringtsuch that:
tis a permutation ofs.- Every occurrence of
yappears before every occurrence ofxint.Return any valid string
t.
3993. Maximum Value of an Alternating Sequence
You are given three integers
n,s, andm.A sequence
seqof integers of lengthnis considered valid if:
seq[0] = s.- The sequence is alternating, meaning that either:
seq[0] > seq[1] < seq[2] > ..., orseq[0] < seq[1] > seq[2] < ....- For every adjacent pair,
|seq[i] - seq[i - 1]| <= m.A sequence of length 1 is considered alternating.
Return the maximum possible element that can appear in any valid sequence.
4001. Aggregate Two Time Series
You are given two 2D integer arrays
series1andseries2.Each element in both series is of the form
[timestamp, value], where:
timestampis an integer representing the time.valueis an integer representing the value at that timestamp.Each array is sorted in strictly increasing order of
timestamp.For any timestamp not present in a series, its value is taken from the next available timestamp in the same series if one exists. Otherwise, its value is considered 0.
The aggregated series is formed by summing the corresponding values from both series at every timestamp that appears in either series.
Return the aggregated series as a 2D integer array of
[timestamp, summedValue]pairs, sorted in strictly increasing order of timestamp.
3994. Minimum Adjacent Swaps to Partition Array
You are given an integer array
numsand two integersaandbsuch thata < b.An array is called good if it can be split into three contiguous parts, in this order, such that:
- Every element in the first part is less than
a.- Every element in the second part is in the range
[a, b]inclusive.- Every element in the third part is greater than
b.Any of the three parts may be empty.
In one adjacent swap, you may swap two neighboring elements of
nums.Return the minimum number of adjacent swaps required to make
numsgood. Since the answer may be very large, return it modulo10^9 + 7.
3995. Minimum Cost to Convert String III
You are given two strings,
sourceandtarget.You are also given a 2D string array
rules, whererules[i] = [pattern_i, replacement_i], and an integer arraycosts, wherecosts[i]is the base cost of applyingrules[i]. Both arrays have the same length. Additionally,pattern_iandreplacement_ihave the same length.You may apply any rule any number of times. Each rule application works as follows:
- Choose an index
lsuch that the range of positions fromltol + pattern_i.length - 1exists in the current string and none of these positions has been used in a previous rule application.- For each index
j, the characterpattern_i[j]must either be equal to the current character at positionl + j, or be'*'.- Replace the characters in this range with
replacement_i. The replacement is used exactly as given and does not contain wildcards.- The cost of this rule application is
costs[i]plus the number of'*'characters inpattern_i.- Once a character position has been used in a rule application, it cannot be used in any later rule application.
Since every
pattern_iandreplacement_ihave the same length, character positions are preserved after every rule application.Return the minimum total cost required to transform
sourceintotarget. If it is impossible, return -1.