
You are given four independent coding questions.
Given a string s (ASCII), count how many characters are uppercase letters ('A'..'Z') and how many are lowercase letters ('a'..'z'). All other characters are ignored.
Return: uppercaseCount - lowercaseCount.
Constraints: 1 ≤ |s| ≤ 1e5.
Given an array nums of n non-negative integers.
Repeat the following operation until all elements are 0:
i
be the smallest index such that
nums[i] > 0
. If no such
i
exists, stop.
x = nums[i]
.
j = i
and moving right, subtract
x
from each
nums[j]
while
j < n
,
nums[j] > 0
, and
nums[j] >= x
.
j
where one of those conditions fails (i.e., you “hit” an element strictly smaller than
x
, or a
0
, or the end of the array).
Each application of steps (1)–(4) counts as one operation.
Task: Return the number of operations needed to make all elements 0.
Constraints: 1 ≤ n ≤ 2e5, 0 ≤ nums[i] ≤ 1e9.
Given an integer array a of length n. You may only increase elements. Increasing a[i] by d ≥ 0 costs d operations.
You want to obtain an array b such that:
b[i] >= a[i]
for all
i
, and
b
is
non-decreasing
(
b[i] <= b[i+1]
)
or
b
is
non-increasing
(
b[i] >= b[i+1]
).
Return: the minimum possible total cost sum_i (b[i] - a[i]) over the better of the two choices (make it non-decreasing or non-increasing).
Constraints: 1 ≤ n ≤ 2e5, |a[i]| ≤ 1e9. Use 64-bit for sums.
You have n batteries. Battery i has:
cap[i]
(minutes of phone runtime when fully charged)
rec[i]
(minutes needed to recharge from empty back to full)
Rules:
0
, all batteries are
fully charged
and available.
T
is reached first).
t
, it immediately starts recharging and becomes available again (fully charged) at time
t + rec[i]
.
Task: Given cap[], rec[], and a wall-clock time limit T, return how many times a battery becomes fully drained during the time interval [0, T].
Constraints (for implementation): 1 ≤ n ≤ 2e5, 1 ≤ cap[i], rec[i] ≤ 1e9, 0 ≤ T ≤ 1e12. Use 64-bit arithmetic.