This question evaluates skills in character classification, array and list manipulation, greedy repartitioning logic, and iterative grid simulation with simultaneous state updates and gravity effects.
You are given three independent coding tasks (as in an online assessment). Implement each as a separate function.
Input: A list of characters chars (each element is a 1-length string).
Output: An integer equal to:
Notes:
isupper()
,
islower()
semantics).
Input: An integer array nums.
Process: Iterate nums from left to right and build two lists A and B.
For each number x:
maxA
be the maximum value currently in
A
(or
if
A
is empty). Let
maxB
be the maximum value currently in
B
(or
if
B
is empty).
maxA > x
or
maxB > x
, append
x
to the list whose current maximum is larger:
maxA >= maxB
, append to
A
; else append to
B
.
x
is at least as large as both current maxima), append
x
to the
shorter
list (if tied, append to
A
).
Output: Return the concatenation A + B.
Input: An n × n integer matrix grid where each positive integer represents a balloon color/label, and 0 represents an empty cell.
Explosion rule (4-neighborhood): For any cell (r, c) with value v > 0, count how many of its up/down/left/right neighbors also have value v. If that count is ≥ 2, then the balloon at (r, c) explodes.
0
.
Gravity rule: After explosions, apply gravity column by column: within each column, all non-zero values fall downward to fill empty spaces, preserving their relative order (stable fall).
Repeat: Repeat “explosion round → gravity” until a full round causes no explosions.
Output: Return the final stabilized grid.
Clarifications: